www.brianhitchcock.net mysql would you like some transactions with that table?

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

Upload: susanna-thomas

Post on 27-Dec-2015

220 views

Category:

Documents


0 download

TRANSCRIPT

www.brianhitchcock.net

MySQL

Would You Like Some Transactions With That Table?

Oct 29, 2009 Page 2www.brianhitchcock.net

Slides Are Available

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 8www.brianhitchcock.net

MySQL Versions

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 13www.brianhitchcock.net

Storage Engines

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 23www.brianhitchcock.net

Binary Logging Formats

Oct 29, 2009 Page 24www.brianhitchcock.net

Binary Log Issues

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 31www.brianhitchcock.net

Documentation Online

Oct 29, 2009 Page 32www.brianhitchcock.net

Documentation Online

Oct 29, 2009 Page 33www.brianhitchcock.net

Documentation Online

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 36www.brianhitchcock.net

Downloads?

Oct 29, 2009 Page 37www.brianhitchcock.net

Downloads?

Oct 29, 2009 Page 38www.brianhitchcock.net

Enterprise Version

Oct 29, 2009 Page 39www.brianhitchcock.net

Community Version

Oct 29, 2009 Page 40www.brianhitchcock.net

Windows Downloads

Oct 29, 2009 Page 41www.brianhitchcock.net

Windows Installation

Oct 29, 2009 Page 42www.brianhitchcock.net

Windows Installation

Oct 29, 2009 Page 43www.brianhitchcock.net

Windows Installation

Oct 29, 2009 Page 44www.brianhitchcock.net

Windows Installation

Oct 29, 2009 Page 45www.brianhitchcock.net

Windows Installation

Oct 29, 2009 Page 46www.brianhitchcock.net

Windows Installation

Oct 29, 2009 Page 47www.brianhitchcock.net

Windows Installation

Oct 29, 2009 Page 48www.brianhitchcock.net

Windows Installation

Oct 29, 2009 Page 49www.brianhitchcock.net

Windows Installation

Oct 29, 2009 Page 50www.brianhitchcock.net

Windows Installation

Uncheck

Oct 29, 2009 Page 51www.brianhitchcock.net

Windows Installation

Oct 29, 2009 Page 52www.brianhitchcock.net

Windows Installation

Check

Oct 29, 2009 Page 53www.brianhitchcock.net

Windows Installation

Oct 29, 2009 Page 54www.brianhitchcock.net

Windows Installation

mysql

Oct 29, 2009 Page 55www.brianhitchcock.net

Windows Installation

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 58www.brianhitchcock.net

mysql client utility

Similar to SQL*Plus

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 62www.brianhitchcock.net

Oct 29, 2009 Page 63www.brianhitchcock.net

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 67www.brianhitchcock.net

Option File

Oct 29, 2009 Page 68www.brianhitchcock.net

Option File

Oct 29, 2009 Page 69www.brianhitchcock.net

Option File

Oct 29, 2009 Page 70www.brianhitchcock.net

Option File

Oct 29, 2009 Page 71www.brianhitchcock.net

Option File

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 73www.brianhitchcock.net

MySQL basedir

Oct 29, 2009 Page 74www.brianhitchcock.net

MySQL basedir/bin

Oct 29, 2009 Page 75www.brianhitchcock.net

MySQL datadir

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 77www.brianhitchcock.net

MySQL Log Files

Find log file locations

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

Oct 29, 2009 Page 79www.brianhitchcock.net

The End?

You now have a MySQL server installed

No excusesLearn it, live it, love itUpdate your resume

Next?Multiple MySQL servers on same machineReplicationetc.