Oct 29, 2009 Page 3www.brianhitchcock.net
What Is MySQL?
Most popular open source RDBMSOpen source means 'free'
Really? No cost at all?
Widely usedSabre – airline reservationsGoogleLinkedIn
What does Oracle DBA need to know?Many differences...
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!
Oct 29, 2009 Page 5www.brianhitchcock.net
Oracle DBA Perspective
What will we look at?InstallingStart/stopHow database/tables storedBackupsTransactions
Storage engines
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'?
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...
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 thing
Recovery Not to worry, plenty more web logs every day
Oct 29, 2009 Page 10www.brianhitchcock.net
Some Differences – MySQL/OracleOracle
Database Schema
a group of database objects Database user
Maps to a database schema
MySQLServer
DatabasesGroup of database objects
Users don't map to database
Oct 29, 2009 Page 11www.brianhitchcock.net
Some Differences – MySQL/OracleStorage enginesTransaction supportPerformanceHot backupBinary logging and recoveryTable lockingCorruptionMisc.
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
Oct 29, 2009 Page 14www.brianhitchcock.net
InnoDB Storage Engine
Imagine mixingMyISAM, InnoDB tables in a statementWhat does 'transactional' mean?What does “recovery” mean?
Oct 29, 2009 Page 15www.brianhitchcock.net
CSV Storage Engine
CSV storage engineStores data in text filesUsing comma-separated format
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'
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
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
Oct 29, 2009 Page 19www.brianhitchcock.net
Performance
Many large MySQL servers in usePerformance must be good
or good enough for 'free'
OptimizerDifferent storage enginesHow to optimize statement that has
MyISAM tables InnoDB tables
Does it support all storage engines you are using?
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
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
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
Oct 29, 2009 Page 25www.brianhitchcock.net
Table Locking
MyISAM storage engineDoes not support row level locking
Table locks
Performance?
InnoDB storage engineSupports row level locking
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?
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/
Oct 29, 2009 Page 28www.brianhitchcock.net
MySQL Issues
MiscReferential Integrity
Some storage engines support
Triggers Row-level, not statement-level
Directload Not supported
Parallel Query Not supported
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
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?
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
Windows
You will have a fully functional MySQL serverStart learning right now
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
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
Oct 29, 2009 Page 57www.brianhitchcock.net
Accessing MySQL Windows
mysql
Shortcut created at installation
Oct 29, 2009 Page 59www.brianhitchcock.net
Now What?Stop, start MySQL server
What databases are availableshow databases;
Set default databaseuse <dbname>
What tables are in the databaseshow tables;
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
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
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
Oct 29, 2009 Page 65www.brianhitchcock.net
MySQL Server ConfigurationControlled by 'option' file(s)
Similar to Oracle pfile or spfileSHOW VARIABLES
See current values
Standard location(s)Search order
One of the most common problemsPersons don't know where these files areMake changes that don't take affectCan't find the file or files
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
Oct 29, 2009 Page 72www.brianhitchcock.net
MySQL Filesystem Layout
From option file (my.ini)basedir
Where software is stored
datadir Where table data is stored
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
Oct 29, 2009 Page 78www.brianhitchcock.net
Summary
MySQL is 'free'May need other products to make it work for you
Hot backup for example
MySQL is widely used
MySQL is very different from OracleDBA tasks and issues will be different
MySQL is not better or worse than OracleJust very different