MySQL (5.5)

The way things are going, I'm not sure the next DB guide I write for Debian is going to have MySQL in the title. Regardless, this hasn't changed too much over the past few years. To make this more straightforward, I have put the MySQL (5.1) specific elements into its own guide.

Todo: This, like most of my guides, is written in first person as for the moment they only reflect my own experience. Should probably focus on filtering that out.

Discussion Elements
What follows is some notes I wrote some years ago (May 2011) on my old blog. Most of it is still relevant, though I've cleaned some things up a bit. My forums are certainly a lot larger now.

MyISAM versus InnoDB
I still see people insisting on using MyISAM. While not garbage, MyISAM has very few advantages, in very limited situations:


 * MyISAM's overhead is smaller, meaning that tables with fixed-width data will be smaller.
 * MyISAM doesn't require a shared tablespace to do tracking, which additionally reduces required disk I/O.
 * While for variable-length tables, InnoDB's compression algorithm can make tables smaller than MyISAM, the superior solution is to compress the data on input.
 * Setting concurrent_insert=2 means that MyISAM will process multiple inserts at a time without issue, no matter what rows are deleted. This isn't an 'advantage' so much as 'not as much of a disadvantage as some claim'.

This makes MyISAM viable for a limited set of activities. Logging, in particular, is a fairly attractive use for MyISAM - not terribly critical, and you are merely appending a lot of data in sequential order. Something which MyISAM is well suited for.

That is about all, however. If your table allows UPDATE statements (editing, pm status updates, and so on), then these will force a table lock. Enough of these occur at once, and your site is effectively down at its most active moments.

Never a good situation.

If the table in question is doing anything besides getting INSERT and DELETE statements, then you should be working with InnoDB.

'New' InnoDB file formats and Compression
This was new four years ago. Still worthy of mention. It is available by default as of the version of InnoDB in 5.4.2.

ignore_builtin_innodb plugin-load=innodb=ha_innodb_plugin.so;innodb_trx=ha_innodb_plugin.so;innodb_locks=ha_innodb_plugin.so;innodb_lock_waits=ha_innodb_plugin.so;innodb_cmp=ha_innodb_plugin.so; innodb_cmp_reset=ha_innodb_plugin.so;innodb_cmpmem=ha_innodb_plugin.so;innodb_cmpmem_reset=ha_innodb_plugin.so default-storage-engine         = InnoDB innodb_file_per_table innodb_file_format             = barracuda
 * 1) InnoDB

Again, the plugin is not needed as of MySQL 5.4.2 in order to enable the new file format or take advantage of other new features in InnoDB. The new Barracuda format requires the use of the innodb_file_per_table option, as the shared tablespace is stored in the original Antelope format.

This format enables two additional row formats for you to store your data in.

Dynamic rows stores long columns (BLOB, TEXT, VARCHAR) that don't fit into a single page as a twenty-byte pointer to the overflow page. When the row size exceeds page size, the longest columns get replaced by the overflow page pointer, until the column fits. This allows InnoDB tables to be more efficient when not actually analyzing these columns, as they do not need to be loaded into the buffer pool. This differs from the previous COMPACT format, which would store the first 768 bytes of these columns in-table, with the 20-byte pointer following, regardless of whether or not it made a good fit.

You can change a table's row format to DYNAMIC by running:

ALTER TABLE table_name ROW_FORMAT=DYNAMIC;

Compressed tables require a bit more discussion. They are basically Dynamic tables, but InnoDB will attempt to compress the contents of a row in a table and see if the results fit in the KEY_BLOCK_SIZE. If they don't, they're stored in the overflow page as with Dynamic, although the overflow page is also compressed. Specifying too large a value of KEY_BLOCK_SIZE will waste some space, but specifying too small a value can cause InnoDB to split nodes needlessly, and a lot of data will be forced into the overflow page. This can dramatically reduce write performance, I have discovered.

mysql> select * from information_schema.INNODB_CMP; +---+--+-+---++-+ | page_size | compress_ops | compress_ops_ok | compress_time | uncompress_ops | uncompress_time | +---+--+-+---++-+ |     1024 |            0 |               0 |             0 |              0 |               0 | |      2048 |            0 |               0 |             0 |              0 |               0 | |      4096 |      3357554 |         1512129 |          1889 |      219238221 |           26632 | |      8192 |      1039670 |         1031859 |           464 |       87310383 |           15538 | |     16384 |            0 |               0 |             0 |              0 |               0 | +---+--+-+---++-+ 5 rows in set (0.00 sec)

Information on using the compression information schema tables can be found here.

In a nutshell, however, you can see that, according to MySQL's documentation, my situation here is not particularly ideal. I have three main compressed tables here:


 * 1) My ajax_chat_messages, with a KEY_BLOCK_SIZE of 4k. These are getting compressed at a somewhat better ratio than raw posts at 4k, but they are still getting compressed - converting them back to DYNAMIC doubled the size of the table on-disk. Converting to 2k increased the size of the table by about 15% from 4k, while decreasing performance massively. Converting them to 8k saw a slight increase in size again, at a massive benefit to performance.
 * 2) My private_messages table, with a KEY_BLOCK_SIZE of 8k. According to MySQL's documentation, compression is working perfectly. Only about half the messages are getting compressed, but it's still a net benefit.
 * 3) My smf_messages table (forum posts), with a KEY_BLOCK_SIZE of 4k. Unlike the above, about three quarters of my member's posts are getting compressed, but of these, only half end up successfully doing so.

Converting the posts table to a key_block_size of 8k means that my posts table is 3,087,007,744 bytes rather than 2,889,875,456 bytes, but the number of successful compressions is far superior:

mysql> select * from information_schema.INNODB_CMP WHERE page_size=8192; +---+--+-+---++-+ | page_size | compress_ops | compress_ops_ok | compress_time | uncompress_ops | uncompress_time | +---+--+-+---++-+ |     8192 |      2365184 |         2351065 |           973 |       95024340 |           16636 | +---+--+-+---++-+ 5 rows in set (0.00 sec)

Meaning, about 200,000 fewer posts actually got compressed (about 1.3 million, leaving out the million compressed private messages), but the overflow page is now far smaller - only about 8,000 private messages and 6,000 posts. This means the overflow pages will be called less, less RAM will be used to store compressed and uncompressed versions of pages, and may mean slightly faster thread views. For the most part, the difference is not too terribly great.

Compression saves me a couple gigabytes over MyISAM, personally - but your mileage will vary. MySQL's documentation on this matter should be taken to heart - overcompression is really, really bad for MySQL. Sustained write rates were an order of magnitude lower than for when compress_ops_ok is ~99% of compress_ops. Whether you see a performance benefit will thus largely depend on how well InnoDB is actually handling the compression. I use less disk space at a key_block_size of 4k on most tables, but it is also dramatically slower.

All things considered, I'm not exactly a fan. This sort of thing should be done in the forum script - not handled by the database. All tables should be stored as dynamic or compact, with their variable-length data gzip-compressed appropriately. This is a matter best addressed with developers, however, and in the mean time, it is a good stopgap measure to improve your disk i/o.

The Query Cache
Suggest this is still useful and get crucified! But... it can be. There are ways to check if the query cache is a net positive or negative for you.

The easiest way to check to see if the Query Cache is doing you any good is to enable it, give it enough space to work with, then check the status of it, e.g.

mysql> show status like 'Qcache%'; +-++ | Variable_name          | Value      | +-++ | Qcache_free_blocks     | 1839       | | Qcache_free_memory     | 94658784   | | Qcache_hits            | 1123738642 | | Qcache_inserts         | 584027197  | | Qcache_lowmem_prunes   | 1775317    | | Qcache_not_cached      | 144840211  | | Qcache_queries_in_cache | 105508    | | Qcache_total_blocks    | 213789     | +-++ 8 rows in set (0.00 sec)

If you are getting lowmem_prunes, you may need to first assign more space to the query cache. In addition, the space you have might be too fragmented for MySQL to work with, necessitating that you regularly run the MySQL command

FLUSH QUERY CACHE;

Every so often. I run it three times an hour through cron. Past that I find it's best to see if there's something I can avoid caching.

Finally, the Query cache limit is generally too high - large queries are much less likely to be repeated, so they just waste space. The solution here is to set query_cache_limit to a lower value - I use 256k:

query_cache_type        = 1 query_cache_limit       = 256K query_cache_size        = 256M query_cache_min_res_unit = 4K
 * 1) Query cache

After you've done this, and after you have assigned 'enough' RAM to the Query Cache - more than 512 megabytes is generally regarded as a bad idea (and most think you should quit far sooner) - check the status after your server has been running for awhile as above.

Qcache_hits / Qcache_inserts = Your Query Cache's effectiveness.

A number less than or equal to one basically means that you aren't actually getting much out of the query cache - on average, the entry gets pruned before it gets used. A number greater than 1 means that the query cache is worthwhile to you - for now.

There is genuine talk of improving the Query Cache's design in future versions of MySQL - or removing it entirely. What is here should be taken as advice for MySQL versions up to 5.5, and possibly further if nothing improves. For my own 20 gigabyte database, however, the query cache is still giving me performance improvements via the above.

Setup and Configuration
What most people will prolly skip to.

Preparation

 * 1) Unless your database server is completely incidental to everything else you are doing, you will want to set up Hugepages. In *nix systems, the amount of memory available is defined in sysctl.conf, and depending on the distribution may also cover access. The performance gain is extremely noticeable, even for sub-gigabyte databases. The exact way to do this may differ with your operating system, so adjust accordingly.
 * 2) Some distributions use a group to designate who can access Hugepages, e.g.
 * 3) usermod -a -G hugepager mysql
 * 4) assuming that's the group you made for it.
 * 5) Debian has its mysqld_safe section in a separate file ( /etc/mysql/conf.d/mysqld_safe_syslog.cnf ) I roll those settings into the main my.cnf file below.
 * 6) Make sure MySQL is shut down before doing the following tasks:
 * 7) If you will be changing the sizes of ib_logfiles, you will need to delete them:
 * 8) rm /var/lib/mysql/ib_logfile0 /var/lib/mysql/ib_logfile1
 * 9) Adjust directory location as needed.
 * 10) If you have mysql-only directories, make sure to chmod 750 and chown user and group to mysql.
 * 11) chmod 0750 /innodb
 * 12) chown mysql:mysql /innodb
 * 13) For example.
 * If, and only if, this is a fresh, virgin installation:
 * 1) Delete your ibdata1 file.
 * 2) If not, you will want to move it if you are using a multi-disk setup. ibdata1 is where the double-buffer log is written (along with a number of other things that get split in future versions of MySQL), and will represent half of your database writes. Because these are all sequential writes, it's fine to stick this on a platter drive.
 * 3) If you are running a master-slave setup, and you are mounting /tmp on tmpfs, you will want to make your own temp directory for MySQL specifically, lest a power failure result in data corruption:

mkdir /mytmp chown mysql:mysql /mytmp chmod 0750 /mytmp

my.cnf
Do not blindly copy and paste this into your my.cnf! Path names in here are for Debian, and might not apply to your Red Hat/CentOS distribution. Moreover, I segregate database load, and you might decide to partition things differently.


 * 1) Obviously you will want to preserve whatever connection settings you
 * 2) have for your distribution. port, socket, user, pid-file, basedir,
 * 3) and other directory settings should only be changed from what your
 * 4) distribution gives you if you know why they should change. In order
 * 5) to prevent silliness I've commented most paths out. Again:


 * 1) I HAVE COMMENTED OUT ALMOST ALL PATH NAMES. BE SURE TO SET YOUR OWN
 * 2) AND SET THEM PROPERLY WHERE YOU NEED TO.


 * 1) YOU SHOULD TAKE YOUR PATH DATA FROM YOUR DEFAULT my.cnf FILE UNLESS
 * 2) YOU KNOW YOU NEED TO CHANGE IT.


 * 1) Ahem.
 * 2) I don't want people blindly copying and pasting then watching things
 * 3) blow up because they are running CentOS or something. These paths
 * 4) won't work in default Debian either.
 * 1) Ideally, you should go from section to section and just pull in the
 * 2) optimizations as you need them.

[client] port            = 3306 [mysqld_safe] nice                    = 0 open-files-limit        = 32768
 * 1) socket          = /run/mysqld/mysqld.sock
 * 1) This was formerly known as [safe_mysqld]. Both versions are currently parsed.
 * 1) socket                   = /run/mysqld/mysqld.sock
 * 1) This open-files-limit is excessive. It's only needed if you insist on
 * 2) staying with MyISAM and then only to crazy levels. I just don't have
 * 3) any reason to remove it.
 * 1) I use log-error rather than syslog. I like error segregation.
 * 2) syslog
 * 3) log-error               = /var/log/mysql/mysql-error.log

[mysqld] user                    = mysql port                    = 3306 skip-external-locking
 * 1) * Basic Settings
 * 1) pid-file                 = /run/mysqld/mysqld.pid
 * 2) socket                   = /run/mysqld/mysqld.sock
 * 1) If you move your database to another directory, you will also have
 * 2) to set it here. You'll want your datadir and ibdata1 files on
 * 3) separate drives, with your ibdata1 preferably on a platter.
 * 4) datadir                  = /data/mysql
 * 5) If you make another temp directory just for MySQL, be sure to mount
 * 6) it tmpfs as with any other temporary directory if this is not a
 * 7) replication slave.
 * 8) If this is a replication slave, you should set this to a directory
 * 9) that survives reboot, so that temporary tables can be successfully
 * 10) replicated. See
 * 11) http://dev.mysql.com/doc/refman/5.1/en/temporary-files.html
 * 12) If this is a slave, be sure to set this to an on-disk temp directory
 * 13) appropriately.
 * 14) tmpdir                   = /tmp
 * 15) language                 = /usr/share/mysql/english

symbolic-links          = 0 local-infile            = 0 automatic_sp_privileges = 0 safe-user-create        = 1 secure-auth             = 1 skip-show-database secure-file-priv        = /tmp
 * 1) Security
 * 2) Symlinks are less of a threat than some of the other things here, but
 * 3) no reason to leave them enabled.
 * 1) No community software I am aware of actually needs LOAD DATA LOCAL,
 * 2) so I just disable it, and probably would not use software that did. See:
 * 3) http://dev.mysql.com/doc/refman/5.1/en/load-data-local.html
 * 1) This prevents granting access to stored procedures automagically just
 * 2) for creating them.
 * 1) safe-user-create prevents autocreating users with the GRANT statement
 * 2) unless the user has the insert privilege on mysql.user
 * 1) secure-auth is probably not relevant if your server was built in the
 * 2) past decade. I just like it on.
 * 1) Remove skip-show-database if you use phpMyAdmin or a similar tool to
 * 2) manage your databases, it will just frustrate you or your users.
 * 1) This limits where the LOAD_FILE, LOAD_DATA and SELECT INTO OUTFILE
 * 2) statements can read from or write to. This is a good option to set.

skip-name-resolve
 * 1) Networking
 * 2) I have replication setup, on a separate interface, so I bind MySQL to
 * 3) a socket and the address for that interface. If you're just using a
 * 4) single machine, use
 * 5) skip-networking
 * 6) instead. Sockets are slightly faster than TCP connections.
 * 7) bind-address            = 192.168.0.1
 * 8) There's no reason to waste time resolving domain names. If the ip
 * 9) changes, we'll know.

large-pages max_allowed_packet      = 32M interactive_timeout     = 3600 wait_timeout            = 300 tmp_table_size          = 32M max_heap_table_size     = 32M table_definition_cache  = 4096 table_open_cache        = 16384 optimizer_search_depth  = 4 character-set-server    = latin1
 * 1) Tuning
 * 2) You will need to enable Hugepages on your server to make use of
 * 3) the large-pages option
 * 1) The client default is 16M, while the server default is 1M. Setting
 * 2) the server to 16M can make some large operations easier.
 * 3) I've since hit 16M limits, so I use 32M now.
 * 1) There's no serious reason to have a long interactive timeout. If you
 * 2) are low on connections, you shouldn't set this higher than
 * 3) wait_timeout
 * 1) I am of the opinion that the default value is far too high. If you
 * 2) use persistent connections, even a timeout of 300 may be too high.
 * 1) The following two are best set to the same size, because the size
 * 2) of temporary tables is limited by the lower of the two.
 * 3) I have not found any benefit in increasing the value past my
 * 4) tmp_table_size default.
 * 1) table_definition_cache should be big enough for every table
 * 2) in your database, plus temporary tables, and table_open_cache
 * 3) should be a reflection of how many of these will be open in a live
 * 4) connection at once - it will likely exceed your definition cache.
 * 5) It doesn't hurt to set these to relatively large values. They don't
 * 6) take a lot of RAM and it's better than hitting the limit.
 * 1) The default optimizer_search_depth is 62. This causes MySQL to take
 * 2) an obscene amount of time planning a query, though when it finally
 * 3) executes, it is pretty close to optimal. Since the vast majority of
 * 4) queries my software runs involve four or fewer relations, I set it
 * 5) to four.
 * 1) I'm not personally a fan of UTF8, multi-byte strings are less
 * 2) efficient and annoying, while websites perform just fine by using
 * 3) ampersand codes to represent nonstandard characters.

join_buffer_size        = 256K sort_buffer_size        = 256K read_buffer_size        = 256K read_rnd_buffer_size    = 2M
 * 1) Buffers
 * 2) 256k for everyone! 256k blocks will generally mean that we are not
 * 3) switching to the rather expensive mmap operation most of the time.
 * 4) read_rnd_buffer can be pretty greedy, at least for my setup.
 * 5) If you are using forums or other software that generates large results,
 * 6) you may find using 2mb is closer to optimal.

thread_stack            = 256K thread_cache_size       = 256 max_connections         = 256
 * 1) Threads
 * 2) 256K is now the default for 64-bit systems, this line is just a
 * 3) legacy from when I had it configured on 32-bits and was following
 * 4) the above advice.
 * 1) max_connections is how many connections your server will tolerate at
 * 2) once, while thread_cache_size is how many of these your server will
 * 3) cache. There is no reason not to set these to be an equal number; I
 * 4) have seen no evidence that the trivial amount of RAM a low
 * 5) thread_cache_size is worth the performance hit of opening up a new
 * 6) thread under load.
 * 7) In realistic terms, you should 'tune to failure' - you don't want
 * 8) to support more active connections than your system can feasibly handle.
 * 9) 256 is a good number for most low-end servers produced these days.
 * 10) Increase if you have multiple drive arrays or faster disks.

query_cache_type        = 1 query_cache_limit       = 256K query_cache_size        = 128M query_cache_min_res_unit = 4K
 * 1) Query cache
 * 2) You may want to check the above info about how useful the
 * 3) Query cache may actually be for you.
 * 4) The only additional point I would make here is that changing
 * 5) query_cache_min_res_unit from the default is effectively useless,
 * 6) especially if you flush regularly like the above article describes.

key_buffer_sie          = 16M key_cache_block_size    = 4K bulk_insert_buffer_size = 8M myisam_sort_buffer_size = 64M myisam-recover-options  = BACKUP concurrent_insert       = 2
 * 1) MyISAM
 * 2) 16M is the most MySQL will store entirely in large-pages. Past that,
 * 3) it will start shunting some of it off to normal memory. Since almost
 * 4) everything I do is InnoDB, this isn't a problem. Otherwise, however,
 * 5) it can make calculating how much space you need difficult.
 * 1) Set this to the size of a filesystem block - e.g. 4k
 * 1) These two should both be the default values. If you are bulk-loading
 * 2) data from a script, you may want to increase bulk_insert_buffer_size
 * 3) to speed up operation.
 * 1) Auto-creates a backup when running the recover operation.
 * 1) By default, MyISAM tables will INSERT into deleted row space before
 * 2) appending to the end of the disk. In exchange for saving this trivial
 * 3) amount of space, once a row gets deleted, only one insert operation
 * 4) may occur at a time until holes are filled. Setting concurrent_insert
 * 5) to 2 stops this silly behavior, at the cost of wasting a bit of disk
 * 6) space, for a significant performance improvement in MyISAM tables.

innodb_buffer_pool_size        = 4096M innodb_autoextend_increment    = 128 innodb_data_file_path          = ibdata1:128M:autoextend innodb_log_files_in_group      = 2 innodb_log_file_size           = 512M innodb_log_buffer_size         = 2M innodb_additional_mem_pool_size = 2M innodb_flush_log_at_trx_commit = 0 innodb_file_per_table innodb_file_format             = barracuda innodb_strict_mode             = 1 innodb_thread_concurrency      = 8 innodb_read_io_threads         = 64 innodb_write_io_threads        = 64 innodb_lock_wait_timeout       = 60 innodb_flush_method            = O_DIRECT
 * 1) InnoDB
 * 2) In theory, you want this to encompass your entire database. In
 * 3) practice, you only have so much RAM available.
 * 4) Fortunately, as long as you can store a big enough chunk that it
 * 5) gets a 99% hit rate, you will be fine.
 * 1) As with everything, only move these if you know you need to.
 * 2) the log_group files belong with the rest of your database. It uses
 * 3) very little io
 * 4) innodb_log_group_home_dir       = /data/mysql
 * 5) ibdata1, on the other hand, will be roughly half of your writes.
 * 6) innodb_data_home_dir            = /innodb
 * 7) I set 128M as the size of ibdata1 because that's how big individual
 * 8) extent entries are in the ext4 filesystem.
 * 1) Supposedly, smaller is better because it makes recovery faster, even
 * 2) if larger means slightly better performance. I have no idea what the
 * 3) logic of this is - if I have a crash, downtime is expected. InnoDB
 * 4) has yet to crash on me in six years.
 * 1) No reason to make the buffers too large, however.
 * 1) Setting innodb_flush_log_at_trx_commit to 0 causes InnoDB to only
 * 2) flush to disk once per second, improving performance considerably.
 * 3) In a community environment, you are more likely to lose a topic
 * 4) read entry or something equally trivial than a post, so the data
 * 5) is very rarely going to be critical, and users often have backups
 * 6) of their own posts.
 * 1) file_per_table makes checking out which tables are doing the heavy
 * 2) lifting a lot easier, for sure. It is also required for the
 * 3) barracuda file format.
 * 1) Note that if you have an established database, and haven't used
 * 2) file_per_table, you'll need to ALTER TABLE each table you want to
 * 3) split off from your ibdata file.
 * 4) Enabling strict mode helps prevent messing up creating or altering
 * 5) a table to support the new row formats in barracuda.
 * 1) I haven't played too much with innodb_thread_concurrency. In my
 * 2) experience, for web purposes at least, Intel architectures work best
 * 3) up to four times the number of cores. Your mileage may vary.
 * 1) Read and write threads - should generally set each of these to
 * 2) four times your -physical- core count (keep in mind that many AMD
 * 3) processors advertize as having double their physical count).
 * 1) I set this to sixty because I have obsessive compulsive disorder.
 * 2) Don't fret over it.
 * 1) O_DIRECT bypasses the operating system's handling of data. This
 * 2) can drastically improve how well your system handles large amounts
 * 3) of RAM by removing double buffers (once in InnoDB's cache, again
 * 4) in the filesystem's cache), at a slight cost to reliability.
 * 5) This appears to be more dramatic the more RAM you have.
 * 6) Note that if you've mounted /tmp to tmpfs like a good admin,
 * 7) InnoDB will whine at you regularly unless you've changed tmpdir to
 * 8) something that isn't tmpfs.
 * 9) Changing tmpdir in such a case only matters for your slave server,
 * 10) but a good idea if you do.

innodb_fast_shutdown = 0
 * 1) We like to be able to do cold backups


 * 1) thread_concurrency is for Solaris only. It does not apply to your
 * 2) Linux box.
 * 3) thread_concurrency    = 10

# # # slow_query_log     = 1 long_query_time    = 1 # server-id                = 1 binlog_cache_size        = 256K sync_binlog              = 16 expire_logs_days         = 7 max_binlog_size          = 512M
 * 1) * Logging and Replication
 * 1) As the default configuration file says, as of 5.1 you can
 * 2) enable the general log at runtime.
 * 3) general_log_file        = /var/log/mysql/mysql.log
 * 4) general_log             = 1
 * 1) Error logging is defined in the mysqld_safe entry.
 * 1) Here you can see queries with especially long duration. Yes,
 * 2) I consider one second to be inordinately long.
 * 1) slow_query_log_file = /var/log/mysql/mysql-slow.log
 * 2) You can set this to non-integer numbers now. One second is rare
 * 3) enough for me that I consider it 'long'.
 * 1) In order to keep your sanity, you may want to only use this when
 * 2) developing software. It would be nice if developers of community
 * 3) software did track this more often.
 * 4) log-queries-not-using-indexes
 * 1) The binlog is mostly for replication, but you may want to set aside
 * 2) a 'small' recovery window like so.
 * 1) log_bin                  = /var/log/mysql/mysql-bin.log
 * 1) Setting sync_binlog fairly high is generally beneficial if the average
 * 2) value of data is fairly small.
 * 1) Statement is the default, but if you turn on replication, you may
 * 2) wish to switch to row-based.
 * 3) binlog_format            = STATEMENT
 * 4) binlog_do_db             = include_database_name
 * 5) binlog_ignore_db         = include_database_name

[mysqldump] quick quote-names max_allowed_packet       = 32M
 * 1) The following items are largely defaults as setup by Debian
 * 2) If you are largely using InnoDB, only the mysqldump section is of
 * 3) any concern.

[mysql] max_allowed_packet       = 32M
 * 1) no-auto-rehash # faster start of mysql but no tab completition
 * 2) Tab completion is a freaking sanity saver.

[isamchk] key_buffer               = 16M


 * 1) Debian likes to put some conf.d nonsense at the end. Your OS might too. Kill it with fire.

Final Touches

 * 1) If you are using the Query Cache, then you will need to setup a cron to flush it regularly, else you are going to see the problems people complain about a lot sooner. First, make an appropriate user:
 * 2) In MySQL:
 * 3) GRANT RELOAD ON *.* TO qcmaint@localhost IDENTIFIED BY 'crazylongpass';
 * 4) In a script file, run
 * 5) /usr/bin/mysql -u qcmaint -p"crazylongpass" -e 'FLUSH QUERY CACHE;'
 * 6) via cron, two to three times an hour. My /etc/cron.d/mysql:
 * 4,24,44 *       *       *       *       root       /root/flushqc.sh
 * 1) My experience is that there is a spot between running it every half hour and every 15 minuts where flushing no longer helps - you should probably stop using the query cache entirely if this breaks down for you.
 * 2) Since root can always set the MySQL password, it can be handy just to stick a giant uncrackable mess in /root/.my.cnf rather than have something crackable:

[client] user=root password=yourrandompasshere socket=/run/mysqld/mysqld.sock