MySQL

79
www.brianhitchcock.n et MySQL Would You Like Some Transactions With That Table?

description

MySQL. Would You Like Some Transactions With That Table?. Slides Are Available. What Is MySQL?. Most popular open source RDBMS Open source means 'free' Really? No cost at all? Widely used Sabre – airline reservations Google LinkedIn What does Oracle DBA need to know? - PowerPoint PPT Presentation

Transcript of MySQL

Page 1: MySQL

www.brianhitchcock.net

MySQL

Would You Like Some Transactions With That Table?

Page 2: MySQL

Oct 29, 2009 Page 2www.brianhitchcock.net

Slides Are Available

Page 3: MySQL

Oct 29, 2009 Page 3www.brianhitchcock.net

What Is MySQL?

Most popular open source RDBMSOpen source means 'free'

Really? No cost at all?Widely used

Sabre – airline reservationsGoogleLinkedIn

What does Oracle DBA need to know?Many differences...

Page 4: MySQL

Oct 29, 2009 Page 4www.brianhitchcock.net

Why Should I Care?

I'm an Oracle DBAMySQL means nothing to meIt isn't a 'real' RDBMS

Why should I learn about MySQL?MySQL is being used by real businessesCan't hurt your employabilityMany jobs expect DBA to know multiple RDBMS

Why not learn one that is widely used? And it's free – you can download and install right now!

Page 5: MySQL

Oct 29, 2009 Page 5www.brianhitchcock.net

Oracle DBA Perspective

What will we look at?InstallingStart/stopHow database/tables storedBackupsTransactions

Storage engines

Page 6: MySQL

Oct 29, 2009 Page 6www.brianhitchcock.net

My Message

Compare MySQL to OracleNot to be critical of MySQLNot to praise OracleMake Oracle DBAs aware

How much we assume about RDBMS Because Oracle does things a certain way

MySQL is very different Assuming it is like Oracle can cause serious problems

Does your business understand the differences? The cost of being 'free'?

Page 7: MySQL

Oct 29, 2009 Page 7www.brianhitchcock.net

MySQL Versions

MySQL EnterpriseHave to buy support

MySQL Community EditionThe 'free' version

MySQL Community Edition Preview ReleaseAvailable for downloadReady for prime time?

Oracle doesn't offer 12g for trial download...

Page 8: MySQL

Oct 29, 2009 Page 8www.brianhitchcock.net

MySQL Versions

Page 9: MySQL

Oct 29, 2009 Page 9www.brianhitchcock.net

MySQL – Where Did It Come From?

Used to store web site logsTransactions

What's that?If we lose some records

So what?Supported by an individual

Do your own thingRecovery

Not to worry, plenty more web logs every day

Page 10: MySQL

Oct 29, 2009 Page 10www.brianhitchcock.net

Some Differences – MySQL/OracleOracle

Database Schema

a group of database objects Database user

Maps to a database schemaMySQL

Server Databases

Group of database objects Users don't map to database

Page 11: MySQL

Oct 29, 2009 Page 11www.brianhitchcock.net

Some Differences – MySQL/OracleStorage enginesTransaction supportPerformanceHot backupBinary logging and recoveryTable lockingCorruptionMisc.

Page 12: MySQL

Oct 29, 2009 Page 12www.brianhitchcock.net

Storage Engines

MySQL gives you a choiceOracle, all transactional all the time (OATATT)

MySQL storage enginesMyISAM (IBM, Indexed Sequential Access Method)

Very fast readInnoDB

Transactional, like Oracle Separate software, owned by Oracle

Many others See next chart

Page 13: MySQL

Oct 29, 2009 Page 13www.brianhitchcock.net

Storage Engines

Page 14: MySQL

Oct 29, 2009 Page 14www.brianhitchcock.net

InnoDB Storage Engine

Imagine mixingMyISAM, InnoDB tables in a statementWhat does 'transactional' mean?What does “recovery” mean?

Page 15: MySQL

Oct 29, 2009 Page 15www.brianhitchcock.net

CSV Storage Engine

CSV storage engineStores data in text filesUsing comma-separated format

Page 16: MySQL

Oct 29, 2009 Page 16www.brianhitchcock.net

Blackhole Storage Engine

My favorite

This is where we store all the data relating to the Raiders andtheir 'Commitment to Excellence'

Page 17: MySQL

Oct 29, 2009 Page 17www.brianhitchcock.net

Yeah, But...

No problemI'll just make all the tables InnoDB

Cool, butMySQL catalog (system?) tables are MyISAMCan't change themTable storage engine can be changed at any time

Privileged users No one should do this, but...stuff happens

Create table syntax Supports overriding default storage engine

Page 18: MySQL

Oct 29, 2009 Page 18www.brianhitchcock.net

Transaction Support

MyISAMDefault table typeTable type of system databasesDoes not support transactionsExample

Writing to MyISAM tables and server crashes Who know what was and wasn't written to tables No recovery

Page 19: MySQL

Oct 29, 2009 Page 19www.brianhitchcock.net

Performance

Many large MySQL servers in usePerformance must be good

or good enough for 'free'Optimizer

Different storage enginesHow to optimize statement that has

MyISAM tables InnoDB tables

Does it support all storage engines you are using?

Page 20: MySQL

Oct 29, 2009 Page 20www.brianhitchcock.net

Hot BackupMySQL does not have this

Backup option #1 Shutdown server, copy all files, startup server

Backup option #2 Lock all tables Dump all data to a dump file

Dump file is set of SQL to recreate databaseVery slow to recover

Backup option #3 Buy hot backup software product

Not free

Page 21: MySQL

Oct 29, 2009 Page 21www.brianhitchcock.net

Binary Logging and Recovery

MySQLDefault, no loggingYou can configure binary loggingThree formats

Statement-based Row-based Mixed

Binary log filenames have format binlog.000001, binlog.000002, etc. You must apply them in correct order

Page 22: MySQL

Oct 29, 2009 Page 22www.brianhitchcock.net

MySQL Binary Logs

MySQL does not have any way of knowing when replaying the binary logs which statements need to be executed and which are already committed.

Oracle DBA doesn't worry about thisOracle checks and tells you which archived redo

log is needed nextOracle won't allow archived redo logs to be applied

out of order

Page 23: MySQL

Oct 29, 2009 Page 23www.brianhitchcock.net

Binary Logging Formats

Page 24: MySQL

Oct 29, 2009 Page 24www.brianhitchcock.net

Binary Log Issues

Page 25: MySQL

Oct 29, 2009 Page 25www.brianhitchcock.net

Table Locking

MyISAM storage engineDoes not support row level locking

Table locksPerformance?

InnoDB storage engineSupports row level locking

Page 26: MySQL

Oct 29, 2009 Page 26www.brianhitchcock.net

CorruptionOracle

I have rarely seen any casesBut all tables support transactions

MySQLWhat does it mean to rollback

When different storage engines involved Some support transactions, some don't Some tables will be rolled back

Others won'tIs this corruption?

Page 27: MySQL

Oct 29, 2009 Page 27www.brianhitchcock.net

MySQL Corruption Issues

Good readDiscusses corruption issues in MySQL enginesI'm not saying this happens often

But you need to be aware of these issues Another difference from Oracle

Different storage engines, different corruption mechanisms

http://www.mysqlperformanceblog.com/2006/07/30/mysql-crash-recovery/

Page 28: MySQL

Oct 29, 2009 Page 28www.brianhitchcock.net

MySQL IssuesMisc

Referential Integrity Some storage engines support

Triggers Row-level, not statement-level

Directload Not supported

Parallel Query Not supported

Page 29: MySQL

Oct 29, 2009 Page 29www.brianhitchcock.net

MySQL Issues

White PaperCompares MySQL to PostgreSQL

PostgreSQL, another open source RDBMS More like Oracle than MySQL

Discusses issues with MySQL I'm not endorsing PostgreSQL But the whitepaper is very good

Google PostgreSQL vs. MySQL A Comparison of Enterprise

Suitability

Page 30: MySQL

Oct 29, 2009 Page 30www.brianhitchcock.net

MySQL Table Storage

MyISAMEach table has three files

<filename>.frm – Data dictonary information <filename>.MYD – table data <filename>.MYI – table indexes

InnoDBData and indexes in a tablespaces

Made up of one or more datafiles Sound familiar?

Page 31: MySQL

Oct 29, 2009 Page 31www.brianhitchcock.net

Documentation Online

Page 32: MySQL

Oct 29, 2009 Page 32www.brianhitchcock.net

Documentation Online

Page 33: MySQL

Oct 29, 2009 Page 33www.brianhitchcock.net

Documentation Online

Page 34: MySQL

Oct 29, 2009 Page 34www.brianhitchcock.net

Talk Is Cheap

A little less conversationA little more action

Download and install MySQL to your laptop nowSlides show the steps

WindowsYou will have a fully functional MySQL server

Start learning right now

Page 35: MySQL

Oct 29, 2009 Page 35www.brianhitchcock.net

Install MySQL – Windows

Windows Vista6.0 Service Pack 1Screenshots shown

Windows XPProfessional Version 5.1Same stepsVery minor differences in what you see

Page 36: MySQL

Oct 29, 2009 Page 36www.brianhitchcock.net

Downloads?

Page 37: MySQL

Oct 29, 2009 Page 37www.brianhitchcock.net

Downloads?

Page 38: MySQL

Oct 29, 2009 Page 38www.brianhitchcock.net

Enterprise Version

Page 39: MySQL

Oct 29, 2009 Page 39www.brianhitchcock.net

Community Version

Page 40: MySQL

Oct 29, 2009 Page 40www.brianhitchcock.net

Windows Downloads

Page 41: MySQL

Oct 29, 2009 Page 41www.brianhitchcock.net

Windows Installation

Page 42: MySQL

Oct 29, 2009 Page 42www.brianhitchcock.net

Windows Installation

Page 43: MySQL

Oct 29, 2009 Page 43www.brianhitchcock.net

Windows Installation

Page 44: MySQL

Oct 29, 2009 Page 44www.brianhitchcock.net

Windows Installation

Page 45: MySQL

Oct 29, 2009 Page 45www.brianhitchcock.net

Windows Installation

Page 46: MySQL

Oct 29, 2009 Page 46www.brianhitchcock.net

Windows Installation

Page 47: MySQL

Oct 29, 2009 Page 47www.brianhitchcock.net

Windows Installation

Page 48: MySQL

Oct 29, 2009 Page 48www.brianhitchcock.net

Windows Installation

Page 49: MySQL

Oct 29, 2009 Page 49www.brianhitchcock.net

Windows Installation

Page 50: MySQL

Oct 29, 2009 Page 50www.brianhitchcock.net

Windows Installation

Uncheck

Page 51: MySQL

Oct 29, 2009 Page 51www.brianhitchcock.net

Windows Installation

Page 52: MySQL

Oct 29, 2009 Page 52www.brianhitchcock.net

Windows Installation

Check

Page 53: MySQL

Oct 29, 2009 Page 53www.brianhitchcock.net

Windows Installation

Page 54: MySQL

Oct 29, 2009 Page 54www.brianhitchcock.net

Windows Installation

mysql

Page 55: MySQL

Oct 29, 2009 Page 55www.brianhitchcock.net

Windows Installation

Page 56: MySQL

Oct 29, 2009 Page 56www.brianhitchcock.net

Accessing MySQL Windows

Click StartProgramsMySQLMySQL Server 5.1MySQL Command Line Client

Right-clickSend to

Desktop (Create Shortcut)Double-click desktop icon

MySQL Command Line Client

Page 57: MySQL

Oct 29, 2009 Page 57www.brianhitchcock.net

Accessing MySQL Windows

mysql

Shortcut created at installation

Page 58: MySQL

Oct 29, 2009 Page 58www.brianhitchcock.net

mysql client utility

Similar to SQL*Plus

Page 59: MySQL

Oct 29, 2009 Page 59www.brianhitchcock.net

Now What?Stop, start MySQL serverWhat databases are available

show databases;Set default database

use <dbname>What tables are in the database

show tables;

Page 60: MySQL

Oct 29, 2009 Page 60www.brianhitchcock.net

Windows Vista

Stop/StartServices

Start Settings Control Panel System and Maintenance Administrative Tools

Services Scroll down to MySQL, highlight Upper left, options for Stop, Pause, Restart If MySQL is down, option to Start

Page 61: MySQL

Oct 29, 2009 Page 61www.brianhitchcock.net

Windows XPStop/Start

Command line net stop mysql, net start mysql

Services Start Control Panel Administrative Tools Services

Services windowScroll down to MySQL, highlightUpper left, options for Stop, Pause, Restart

If MySQL is down, option to Start

Page 62: MySQL

Oct 29, 2009 Page 62www.brianhitchcock.net

Page 63: MySQL

Oct 29, 2009 Page 63www.brianhitchcock.net

Page 64: MySQL

Oct 29, 2009 Page 64www.brianhitchcock.net

System Databases

INFORMATION_SCHEMACatalog database

MYSQL databaseUser and privilege information

TESTFor you to play in...

These databases are created at installation

Page 65: MySQL

Oct 29, 2009 Page 65www.brianhitchcock.net

MySQL Server ConfigurationControlled by 'option' file(s)

Similar to Oracle pfile or spfileSHOW VARIABLES

See current valuesStandard location(s)

Search orderOne of the most common problems

Persons don't know where these files areMake changes that don't take affectCan't find the file or files

Page 66: MySQL

Oct 29, 2009 Page 66www.brianhitchcock.net

Option File(s)MySQL searches multiple locations

Uses most recent value of each parameterHow to know all files being scanned by MySQL?

mysql –help

Note: dash dash help

Page 67: MySQL

Oct 29, 2009 Page 67www.brianhitchcock.net

Option File

Page 68: MySQL

Oct 29, 2009 Page 68www.brianhitchcock.net

Option File

Page 69: MySQL

Oct 29, 2009 Page 69www.brianhitchcock.net

Option File

Page 70: MySQL

Oct 29, 2009 Page 70www.brianhitchcock.net

Option File

Page 71: MySQL

Oct 29, 2009 Page 71www.brianhitchcock.net

Option File

Page 72: MySQL

Oct 29, 2009 Page 72www.brianhitchcock.net

MySQL Filesystem LayoutFrom option file (my.ini)

basedir Where software is stored

datadir Where table data is stored

Page 73: MySQL

Oct 29, 2009 Page 73www.brianhitchcock.net

MySQL basedir

Page 74: MySQL

Oct 29, 2009 Page 74www.brianhitchcock.net

MySQL basedir/bin

Page 75: MySQL

Oct 29, 2009 Page 75www.brianhitchcock.net

MySQL datadir

Page 76: MySQL

Oct 29, 2009 Page 76www.brianhitchcock.net

MySQL Log Files

General Query LogAll client requests

Binary LogStatements that modify data

Slow Query LogStatements that take longer than 10 seconds

Error LogServer messages

Page 77: MySQL

Oct 29, 2009 Page 77www.brianhitchcock.net

MySQL Log Files

Find log file locations

Page 78: MySQL

Oct 29, 2009 Page 78www.brianhitchcock.net

Summary

MySQL is 'free'May need other products to make it work for you

Hot backup for exampleMySQL is widely usedMySQL is very different from Oracle

DBA tasks and issues will be differentMySQL is not better or worse than Oracle

Just very different

Page 79: MySQL

Oct 29, 2009 Page 79www.brianhitchcock.net

The End?

You now have a MySQL server installedNo excuses

Learn it, live it, love itUpdate your resume

Next?Multiple MySQL servers on same machineReplicationetc.