Filed Under (Coding, Databases) by steve on 28-07-2009

I’m currently reading High Performance MySQL by Schwartz, Zaitsev, Tkachenko, Zawodny, Lentz, Balling

Great, in-depth material on everything related to customizing your MySQL Database configuration, and a plethora of info on all of the many, many ways and tools available, for measuring, profiling, analyzing your database.

If you’re strictly an “end user” type programmer of MySQL (versus being a DBA), and have only ever created the basic tables without attention to specifics, and without knowing what the defaults are, etc..
    I summarized some under-the-hood facts that might help with getting more out of MySQL than you’re used to.

1. Tuning the MySQL Server

According to dev.mysql.com,
the two most important variables are key_buffer_size and table_cache. These are configured in the my.cnf file (on Unix platform).

In exact words:

When tuning a MySQL server, the two most important variables to configure are key_buffer_size and table_cache. You should first feel confident that you have these set appropriately before trying to change any other variables.

2. What are storage engines? i.e.: MyISAM,, InnoDB, etc…

The storage engine is the third layer in the total structure of how a MySQL database is organized. It handles the retrieving and storing of data only. The fact that it is separated from the 2nd layer ( where all the major MySQL brains are located ) means that you can use different storage engines per table.

3. Which one is used by default if you don’t specify the type?

MyISAM

4. A chart of some basic differences between the 2 most common engines:

Feature MyISAM InnoDB
Transactions No Yes
Foreign Key Constraints No Yes
Known for High Concurrency No Yes
Full-text Searching Yes No
Compression Yes No
Row-level Locking No Yes

5. Finally, here’s a list of ways to decide which storage engine to use

Your Application will probably need/involve: Most likely use Engine:
Transactions InnoDB
.. to handle mostly just Selects and Inserts is MyISAM
.. more of a mixture of operations, including concurrent updates (i.e. more than just selects and inserts like the above) InnoDB (due to its row-locking)
.. more stability due to handling very large amounts of data Since MyISAM leads to data becoming corrupt easier and takes longer to recover data than InnoDB, use InnoDB

This was meant as a motivator to consider slowing up the database portion of your application development so that your storage engine choices make sense for your app’s needs. (Its possible to change a table’s storage engine later.)

There’s way more than what I summarized above, obviously. Would advise reading dev.mysql.com and/or google groups devoted to mysql.



Post a comment
Name: 
Email: 
URL: 
Comments: