www.brianhitchcock.net
MySQL
Would You Like Some Transactions
With That Table?
www.brianhitchcock.netOct 29, 2009 Page 2
Slides Are Available
www.brianhitchcock.netOct 29, 2009 Page 3
What Is MySQL?
Most popular open source RDBMS
 Open source means 'free'
 Real...
www.brianhitchcock.netOct 29, 2009 Page 4
Why Should I Care?
I'm an Oracle DBA
 MySQL means nothing to me
 It isn't a '...
www.brianhitchcock.netOct 29, 2009 Page 5
Oracle DBA Perspective
What will we look at?
 Installing
 Start/stop
 How da...
www.brianhitchcock.netOct 29, 2009 Page 6
My Message
Compare MySQL to Oracle
 Not to be critical of MySQL
 Not to prais...
www.brianhitchcock.netOct 29, 2009 Page 7
MySQL Versions
MySQL Enterprise
 Have to buy support
MySQL Community Edition
...
www.brianhitchcock.netOct 29, 2009 Page 8
MySQL Versions
www.brianhitchcock.netOct 29, 2009 Page 9
MySQL – Where Did It Come From?
Used to store web site logs
 Transactions
 Wh...
www.brianhitchcock.netOct 29, 2009 Page 10
Some Differences – MySQL/Oracle
Oracle
 Database
 Schema
a group of databas...
www.brianhitchcock.netOct 29, 2009 Page 11
Some Differences – MySQL/Oracle
Storage engines
Transaction support
Performa...
www.brianhitchcock.netOct 29, 2009 Page 12
Storage Engines
MySQL gives you a choice
 Oracle, all transactional all the t...
www.brianhitchcock.netOct 29, 2009 Page 13
Storage Engines
www.brianhitchcock.netOct 29, 2009 Page 14
InnoDB Storage Engine
Imagine mixing
 MyISAM, InnoDB tables in a statement
 ...
www.brianhitchcock.netOct 29, 2009 Page 15
CSV Storage Engine
CSV storage engine
 Stores data in text files
 Using comm...
www.brianhitchcock.netOct 29, 2009 Page 16
Blackhole Storage Engine
My favorite
This is where we store all the data relat...
www.brianhitchcock.netOct 29, 2009 Page 17
Yeah, But...
No problem
 I'll just make all the tables InnoDB
Cool, but
 My...
www.brianhitchcock.netOct 29, 2009 Page 18
Transaction Support
MyISAM
 Default table type
 Table type of system databas...
www.brianhitchcock.netOct 29, 2009 Page 19
Performance
Many large MySQL servers in use
 Performance must be good
or good...
www.brianhitchcock.netOct 29, 2009 Page 20
Hot Backup
MySQL does not have this
 Backup option #1
 Shutdown server, copy...
www.brianhitchcock.netOct 29, 2009 Page 21
Binary Logging and Recovery
MySQL
 Default, no logging
 You can configure bi...
www.brianhitchcock.netOct 29, 2009 Page 22
MySQL Binary Logs
MySQL does not have any way of knowing
when replaying the bi...
www.brianhitchcock.netOct 29, 2009 Page 23
Binary Logging Formats
www.brianhitchcock.netOct 29, 2009 Page 24
Binary Log Issues
www.brianhitchcock.netOct 29, 2009 Page 25
Table Locking
MyISAM storage engine
 Does not support row level locking
 Tab...
www.brianhitchcock.netOct 29, 2009 Page 26
Corruption
Oracle
 I have rarely seen any cases
 But all tables support tran...
www.brianhitchcock.netOct 29, 2009 Page 27
MySQL Corruption Issues
Good read
 Discusses corruption issues in MySQL engin...
www.brianhitchcock.netOct 29, 2009 Page 28
MySQL Issues
Misc
 Referential Integrity
 Some storage engines support
 Tri...
www.brianhitchcock.netOct 29, 2009 Page 29
MySQL Issues
White Paper
 Compares MySQL to PostgreSQL
 PostgreSQL, another ...
www.brianhitchcock.netOct 29, 2009 Page 30
MySQL Table Storage
MyISAM
 Each table has three files
 <filename>.frm – Dat...
www.brianhitchcock.netOct 29, 2009 Page 31
Documentation Online
www.brianhitchcock.netOct 29, 2009 Page 32
Documentation Online
www.brianhitchcock.netOct 29, 2009 Page 33
Documentation Online
www.brianhitchcock.netOct 29, 2009 Page 34
Talk Is Cheap
A little less conversation
 A little more action
Download and ...
www.brianhitchcock.netOct 29, 2009 Page 35
Install MySQL – Windows
Windows Vista
 6.0 Service Pack 1
 Screenshots shown...
www.brianhitchcock.netOct 29, 2009 Page 36
Downloads?
www.brianhitchcock.netOct 29, 2009 Page 37
Downloads?
www.brianhitchcock.netOct 29, 2009 Page 38
Enterprise Version
www.brianhitchcock.netOct 29, 2009 Page 39
Community Version
www.brianhitchcock.netOct 29, 2009 Page 40
Windows Downloads
www.brianhitchcock.netOct 29, 2009 Page 41
Windows Installation
www.brianhitchcock.netOct 29, 2009 Page 42
Windows Installation
www.brianhitchcock.netOct 29, 2009 Page 43
Windows Installation
www.brianhitchcock.netOct 29, 2009 Page 44
Windows Installation
www.brianhitchcock.netOct 29, 2009 Page 45
Windows Installation
www.brianhitchcock.netOct 29, 2009 Page 46
Windows Installation
www.brianhitchcock.netOct 29, 2009 Page 47
Windows Installation
www.brianhitchcock.netOct 29, 2009 Page 48
Windows Installation
www.brianhitchcock.netOct 29, 2009 Page 49
Windows Installation
www.brianhitchcock.netOct 29, 2009 Page 50
Windows Installation
Uncheck
www.brianhitchcock.netOct 29, 2009 Page 51
Windows Installation
www.brianhitchcock.netOct 29, 2009 Page 52
Windows Installation
Check
www.brianhitchcock.netOct 29, 2009 Page 53
Windows Installation
www.brianhitchcock.netOct 29, 2009 Page 54
Windows Installation
mysql
www.brianhitchcock.netOct 29, 2009 Page 55
Windows Installation
www.brianhitchcock.netOct 29, 2009 Page 56
Accessing MySQL Windows
Click Start
 Programs
 MySQL
 MySQL Server 5.1
 My...
www.brianhitchcock.netOct 29, 2009 Page 57
Accessing MySQL Windows
mysql
Shortcut created at installation
www.brianhitchcock.netOct 29, 2009 Page 58
mysql client utility
Similar to SQL*Plus
www.brianhitchcock.netOct 29, 2009 Page 59
Now What?
Stop, start MySQL server
What databases are available
 show databa...
www.brianhitchcock.netOct 29, 2009 Page 60
Windows Vista
Stop/Start
 Services
 Start
 Settings
 Control Panel
 Syste...
www.brianhitchcock.netOct 29, 2009 Page 61
Windows XP
Stop/Start
 Command line
 net stop mysql, net start mysql
 Servi...
www.brianhitchcock.netOct 29, 2009 Page 62
www.brianhitchcock.netOct 29, 2009 Page 63
www.brianhitchcock.netOct 29, 2009 Page 64
System Databases
INFORMATION_SCHEMA
 Catalog database
MYSQL database
 User ...
www.brianhitchcock.netOct 29, 2009 Page 65
MySQL Server Configuration
Controlled by 'option' file(s)
 Similar to Oracle ...
www.brianhitchcock.netOct 29, 2009 Page 66
Option File(s)
MySQL searches multiple locations
 Uses most recent value of e...
www.brianhitchcock.netOct 29, 2009 Page 67
Option File
www.brianhitchcock.netOct 29, 2009 Page 68
Option File
www.brianhitchcock.netOct 29, 2009 Page 69
Option File
www.brianhitchcock.netOct 29, 2009 Page 70
Option File
www.brianhitchcock.netOct 29, 2009 Page 71
Option File
www.brianhitchcock.netOct 29, 2009 Page 72
MySQL Filesystem Layout
From option file (my.ini)
 basedir
 Where software i...
www.brianhitchcock.netOct 29, 2009 Page 73
MySQL basedir
www.brianhitchcock.netOct 29, 2009 Page 74
MySQL basedir/bin
www.brianhitchcock.netOct 29, 2009 Page 75
MySQL datadir
www.brianhitchcock.netOct 29, 2009 Page 76
MySQL Log Files
General Query Log
 All client requests
Binary Log
 Statemen...
www.brianhitchcock.netOct 29, 2009 Page 77
MySQL Log Files
Find log file locations
www.brianhitchcock.netOct 29, 2009 Page 78
Summary
MySQL is 'free'
 May need other products to make it work for you
 Ho...
www.brianhitchcock.netOct 29, 2009 Page 79
The End?
You now have a MySQL server installed
No excuses
 Learn it, live it...
Upcoming SlideShare
Loading in...5
×

My sql would you like transactions

237

Published on

MySQL Would You Like Transactions

http://www.ossez.com/forum.php?mod=viewthread&tid=26897&fromuid=426
(出处: OSSEZ)

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
237
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

My sql would you like transactions

  1. 1. www.brianhitchcock.net MySQL Would You Like Some Transactions With That Table?
  2. 2. www.brianhitchcock.netOct 29, 2009 Page 2 Slides Are Available
  3. 3. www.brianhitchcock.netOct 29, 2009 Page 3 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?  Many differences...
  4. 4. www.brianhitchcock.netOct 29, 2009 Page 4 Why Should I Care? I'm an Oracle DBA  MySQL means nothing to me  It isn't a 'real' RDBMS Why should I learn about MySQL?  MySQL is being used by real businesses  Can't hurt your employability  Many 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!
  5. 5. www.brianhitchcock.netOct 29, 2009 Page 5 Oracle DBA Perspective What will we look at?  Installing  Start/stop  How database/tables stored  Backups  Transactions  Storage engines
  6. 6. www.brianhitchcock.netOct 29, 2009 Page 6 My Message Compare MySQL to Oracle  Not to be critical of MySQL  Not to praise Oracle  Make 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'?
  7. 7. www.brianhitchcock.netOct 29, 2009 Page 7 MySQL Versions MySQL Enterprise  Have to buy support MySQL Community Edition  The 'free' version MySQL Community Edition Preview Release  Available for download  Ready for prime time?  Oracle doesn't offer 12g for trial download...
  8. 8. www.brianhitchcock.netOct 29, 2009 Page 8 MySQL Versions
  9. 9. www.brianhitchcock.netOct 29, 2009 Page 9 MySQL – Where Did It Come From? Used to store web site logs  Transactions  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
  10. 10. www.brianhitchcock.netOct 29, 2009 Page 10 Some Differences – MySQL/Oracle Oracle  Database  Schema a group of database objects  Database user Maps to a database schema MySQL  Server  Databases Group of database objects  Users don't map to database
  11. 11. www.brianhitchcock.netOct 29, 2009 Page 11 Some Differences – MySQL/Oracle Storage engines Transaction support Performance Hot backup Binary logging and recovery Table locking Corruption Misc.
  12. 12. www.brianhitchcock.netOct 29, 2009 Page 12 Storage Engines MySQL gives you a choice  Oracle, all transactional all the time (OATATT) MySQL storage engines  MyISAM (IBM, Indexed Sequential Access Method)  Very fast read  InnoDB  Transactional, like Oracle  Separate software, owned by Oracle  Many others  See next chart
  13. 13. www.brianhitchcock.netOct 29, 2009 Page 13 Storage Engines
  14. 14. www.brianhitchcock.netOct 29, 2009 Page 14 InnoDB Storage Engine Imagine mixing  MyISAM, InnoDB tables in a statement  What does 'transactional' mean?  What does “recovery” mean?
  15. 15. www.brianhitchcock.netOct 29, 2009 Page 15 CSV Storage Engine CSV storage engine  Stores data in text files  Using comma-separated format
  16. 16. www.brianhitchcock.netOct 29, 2009 Page 16 Blackhole Storage Engine My favorite This is where we store all the data relating to the Raiders and their 'Commitment to Excellence'
  17. 17. www.brianhitchcock.netOct 29, 2009 Page 17 Yeah, But... No problem  I'll just make all the tables InnoDB Cool, but  MySQL catalog (system?) tables are MyISAM  Can't change them  Table 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
  18. 18. www.brianhitchcock.netOct 29, 2009 Page 18 Transaction Support MyISAM  Default table type  Table type of system databases  Does not support transactions  Example  Writing to MyISAM tables and server crashes  Who know what was and wasn't written to tables  No recovery
  19. 19. www.brianhitchcock.netOct 29, 2009 Page 19 Performance Many large MySQL servers in use  Performance must be good or good enough for 'free' Optimizer  Different storage engines  How to optimize statement that has  MyISAM tables  InnoDB tables  Does it support all storage engines you are using?
  20. 20. www.brianhitchcock.netOct 29, 2009 Page 20 Hot Backup MySQL 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 database Very slow to recover  Backup option #3  Buy hot backup software product Not free
  21. 21. www.brianhitchcock.netOct 29, 2009 Page 21 Binary Logging and Recovery MySQL  Default, no logging  You can configure binary logging  Three formats  Statement-based  Row-based  Mixed  Binary log filenames have format  binlog.000001, binlog.000002, etc.  You must apply them in correct order
  22. 22. www.brianhitchcock.netOct 29, 2009 Page 22 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 this  Oracle checks and tells you which archived redo log is needed next  Oracle won't allow archived redo logs to be applied out of order
  23. 23. www.brianhitchcock.netOct 29, 2009 Page 23 Binary Logging Formats
  24. 24. www.brianhitchcock.netOct 29, 2009 Page 24 Binary Log Issues
  25. 25. www.brianhitchcock.netOct 29, 2009 Page 25 Table Locking MyISAM storage engine  Does not support row level locking  Table locks  Performance? InnoDB storage engine  Supports row level locking
  26. 26. www.brianhitchcock.netOct 29, 2009 Page 26 Corruption Oracle  I have rarely seen any cases  But all tables support transactions MySQL  What does it mean to rollback  When different storage engines involved  Some support transactions, some don't  Some tables will be rolled back Others won't  Is this corruption?
  27. 27. www.brianhitchcock.netOct 29, 2009 Page 27 MySQL Corruption Issues Good read  Discusses corruption issues in MySQL engines  I'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/
  28. 28. www.brianhitchcock.netOct 29, 2009 Page 28 MySQL Issues Misc  Referential Integrity  Some storage engines support  Triggers  Row-level, not statement-level  Directload  Not supported  Parallel Query  Not supported
  29. 29. www.brianhitchcock.netOct 29, 2009 Page 29 MySQL Issues White Paper  Compares 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
  30. 30. www.brianhitchcock.netOct 29, 2009 Page 30 MySQL Table Storage MyISAM  Each table has three files  <filename>.frm – Data dictonary information  <filename>.MYD – table data  <filename>.MYI – table indexes InnoDB  Data and indexes in a tablespaces  Made up of one or more datafiles  Sound familiar?
  31. 31. www.brianhitchcock.netOct 29, 2009 Page 31 Documentation Online
  32. 32. www.brianhitchcock.netOct 29, 2009 Page 32 Documentation Online
  33. 33. www.brianhitchcock.netOct 29, 2009 Page 33 Documentation Online
  34. 34. www.brianhitchcock.netOct 29, 2009 Page 34 Talk Is Cheap A little less conversation  A little more action Download and install MySQL to your laptop now  Slides show the steps  Windows You will have a fully functional MySQL server  Start learning right now
  35. 35. www.brianhitchcock.netOct 29, 2009 Page 35 Install MySQL – Windows Windows Vista  6.0 Service Pack 1  Screenshots shown Windows XP  Professional Version 5.1  Same steps  Very minor differences in what you see
  36. 36. www.brianhitchcock.netOct 29, 2009 Page 36 Downloads?
  37. 37. www.brianhitchcock.netOct 29, 2009 Page 37 Downloads?
  38. 38. www.brianhitchcock.netOct 29, 2009 Page 38 Enterprise Version
  39. 39. www.brianhitchcock.netOct 29, 2009 Page 39 Community Version
  40. 40. www.brianhitchcock.netOct 29, 2009 Page 40 Windows Downloads
  41. 41. www.brianhitchcock.netOct 29, 2009 Page 41 Windows Installation
  42. 42. www.brianhitchcock.netOct 29, 2009 Page 42 Windows Installation
  43. 43. www.brianhitchcock.netOct 29, 2009 Page 43 Windows Installation
  44. 44. www.brianhitchcock.netOct 29, 2009 Page 44 Windows Installation
  45. 45. www.brianhitchcock.netOct 29, 2009 Page 45 Windows Installation
  46. 46. www.brianhitchcock.netOct 29, 2009 Page 46 Windows Installation
  47. 47. www.brianhitchcock.netOct 29, 2009 Page 47 Windows Installation
  48. 48. www.brianhitchcock.netOct 29, 2009 Page 48 Windows Installation
  49. 49. www.brianhitchcock.netOct 29, 2009 Page 49 Windows Installation
  50. 50. www.brianhitchcock.netOct 29, 2009 Page 50 Windows Installation Uncheck
  51. 51. www.brianhitchcock.netOct 29, 2009 Page 51 Windows Installation
  52. 52. www.brianhitchcock.netOct 29, 2009 Page 52 Windows Installation Check
  53. 53. www.brianhitchcock.netOct 29, 2009 Page 53 Windows Installation
  54. 54. www.brianhitchcock.netOct 29, 2009 Page 54 Windows Installation mysql
  55. 55. www.brianhitchcock.netOct 29, 2009 Page 55 Windows Installation
  56. 56. www.brianhitchcock.netOct 29, 2009 Page 56 Accessing MySQL Windows Click Start  Programs  MySQL  MySQL Server 5.1  MySQL Command Line Client  Right-click Send to  Desktop (Create Shortcut) Double-click desktop icon  MySQL Command Line Client
  57. 57. www.brianhitchcock.netOct 29, 2009 Page 57 Accessing MySQL Windows mysql Shortcut created at installation
  58. 58. www.brianhitchcock.netOct 29, 2009 Page 58 mysql client utility Similar to SQL*Plus
  59. 59. www.brianhitchcock.netOct 29, 2009 Page 59 Now What? Stop, start MySQL server What databases are available  show databases; Set default database  use <dbname> What tables are in the database  show tables;
  60. 60. www.brianhitchcock.netOct 29, 2009 Page 60 Windows Vista Stop/Start  Services  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
  61. 61. www.brianhitchcock.netOct 29, 2009 Page 61 Windows XP Stop/Start  Command line  net stop mysql, net start mysql  Services  Start  Control Panel  Administrative Tools  Services Services window Scroll down to MySQL, highlight Upper left, options for Stop, Pause, Restart  If MySQL is down, option to Start
  62. 62. www.brianhitchcock.netOct 29, 2009 Page 62
  63. 63. www.brianhitchcock.netOct 29, 2009 Page 63
  64. 64. www.brianhitchcock.netOct 29, 2009 Page 64 System Databases INFORMATION_SCHEMA  Catalog database MYSQL database  User and privilege information TEST  For you to play in... These databases are created at installation
  65. 65. www.brianhitchcock.netOct 29, 2009 Page 65 MySQL Server Configuration Controlled by 'option' file(s)  Similar to Oracle pfile or spfile  SHOW VARIABLES  See current values Standard location(s)  Search order One of the most common problems  Persons don't know where these files are  Make changes that don't take affect  Can't find the file or files
  66. 66. www.brianhitchcock.netOct 29, 2009 Page 66 Option File(s) MySQL searches multiple locations  Uses most recent value of each parameter  How to know all files being scanned by MySQL?  mysql –help Note: dash dash help
  67. 67. www.brianhitchcock.netOct 29, 2009 Page 67 Option File
  68. 68. www.brianhitchcock.netOct 29, 2009 Page 68 Option File
  69. 69. www.brianhitchcock.netOct 29, 2009 Page 69 Option File
  70. 70. www.brianhitchcock.netOct 29, 2009 Page 70 Option File
  71. 71. www.brianhitchcock.netOct 29, 2009 Page 71 Option File
  72. 72. www.brianhitchcock.netOct 29, 2009 Page 72 MySQL Filesystem Layout From option file (my.ini)  basedir  Where software is stored  datadir  Where table data is stored
  73. 73. www.brianhitchcock.netOct 29, 2009 Page 73 MySQL basedir
  74. 74. www.brianhitchcock.netOct 29, 2009 Page 74 MySQL basedir/bin
  75. 75. www.brianhitchcock.netOct 29, 2009 Page 75 MySQL datadir
  76. 76. www.brianhitchcock.netOct 29, 2009 Page 76 MySQL Log Files General Query Log  All client requests Binary Log  Statements that modify data Slow Query Log  Statements that take longer than 10 seconds Error Log  Server messages
  77. 77. www.brianhitchcock.netOct 29, 2009 Page 77 MySQL Log Files Find log file locations
  78. 78. www.brianhitchcock.netOct 29, 2009 Page 78 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 Oracle  DBA tasks and issues will be different MySQL is not better or worse than Oracle  Just very different
  79. 79. www.brianhitchcock.netOct 29, 2009 Page 79 The End? You now have a MySQL server installed No excuses  Learn it, live it, love it  Update your resume Next?  Multiple MySQL servers on same machine  Replication  etc.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×