As MySQL is the internet and cloud de-facto database, we dedicate another post regarding what should you do before getting to the money time.
Some methods including stored data compression and splitting the InnoDB storage file are covered in this post.
Compressing the File
InnoDB data compression is possible in a way that is very similar to disk compression with the pros and cons of it. This method is defined in the table declaration statement and explained in the MySQL documentation. Will it improve MySQL performance? Fortunately, the answer is yes! a recent post by MySQL@Facebook team shown a 10% boost in response time and improvement in the cache hit ratio.
Splitting the Storage File
The default InnoDB configuration is using a single file named ibdata1. This file stores both data and configuration. The bad news is that this file always expands and cannot be shrinked.
Usually people notice this fact when the database is getting too large and they have some storage or backup issues. Usually in these cases, the system is already in production and cannot suffer downtime. Therefore, you should take care of splitting this file in the early days of the system rather when you are in the money time.
What to do?
- Configure the MySQL to save the data in various files, one per table. Please notice that this will work only to tables that will be created from now on. Perform that by adding for following lines to the my.cnf file:
- Stop the server for maintenance and perform one of the following three methods:
- Convert all InnoDB tables to MyISAM and back
- Export only InnoDB tables, drop them, delete ibdata1 and import InnoDB tables.
- Export all databases, delete ibdata1 and import everything back.
- I recommends you to choose option 2 and perform it according to the following procedure: export-delete-import:
- mysqldump to the whole database.
- Stop the MySQL daemon.
- Delete the ibdata + ilog files.
- Delete the database folders (all except for MySQL).
- Change my.cnf file if needed.
- Restart the MySQL daemon.
- Import the dumped file back to the system.
Some times, it wise to perform tasks earlier in order to avoid complex issues in the future.