Optimization is
a difficult task because to optimize a system you must know the in
and out of it. You can optimize your system easily if have knowledge
or understanding of your system. In MySQL the main performance
booster is query optimization. Although other factors are also
important in improving performance but by optimizing query you will
see drastic impact on execution time. So here I am discussing some
quick tips for improving MySQL performance.
Tips: For
MySQL OS & hardware
- Avoid reading data from disk as it is very slow process.
- Use SAS instead of SATA.
- Avoid using lower versions of RAID.
- Never try to kill a MysQL process forcefully otherwise you will loose your data.
- Use smaller disks as they are much faster than larger disks.
- Your server should be dedicated to MySQL only.
- Make sure your OS and data partitions are physically seperated.
- Avoid using software RAIDS.
Tips: For
MySQL schema optimization
- Use indexes to speed things up but don't overdo it.
- Instead of adding new indexes, always try to extend the existing ones.
- Use triggers.
- Use storage engine according to your data requirements.
- Optimize tables.
- If you are storing variable length strings use VARCHAR instead of CHAR.
- Use more linking tables.
- Try to use the smallest data type.
- If your database has auditing tables then use ARCHIVE storage engine.
- Try to avoid using NULL because when it indexed it take an extra byte per entry.
Tips: For
MySQL backups
- When taking backup of database make sure MySQL is closed.
- Optimize all the table before backup.
- Don't use replication during backup as it can make data inconsistent.
- If you backup data using mysqldump then use it with -opt.
- Check the size of tables, indexes and database after backup to monitor growth.
- Test your backups weekly to make sure they are working properly.
- Avoid using LVM snapshot for backup as it can make your data inconsistent.
Tips: For
MySQL query optimization
- Normalize all the tables.
- Use 'OPTIMIZE TABLE' and 'REPAIR TABLE COMMAND' to improve the loading speed of your database.
- Find out the slow queries in your database using Slow Query Log.
- After identify the slow queries, use commands like EXPLAIN, SHOWPROCESS LIST to check the functionality of queries and their side effects on database.
- Avoid using HAVING clause.
- Use TRUNCATE command instead of DELETE for removing entire table.
- Try to use GROUP BY rather than DISTINCT when required.
- Count (*) can lock the entire table, so avoid using it.
- Avoid MAX command instead use ORDER BY.
- Use UNION in sub queries.
- To remove table use DROP TABLE command instead of DELETE FROM.
These are the
basic things that you can do to optimize MySQL. I hope it will help you.
If you too want to share some tips, please go ahead.
No comments:
Post a Comment