We are 50+ professional Software Developers with more than 5+ years of experience in delivering solutions.

Contacts

B-1001, PNTC, Prahalad Nagar, Ahmedabad

+91 63548-55130 | +1 707-901-7072

Laravel laravel.tips MySQL
Top 08 hack for Boost MySQL Performance

Top 08 hack for Boost MySQL Performance

What you Learn, MySQL

  1. Use The InnoDB Storage Engine not MyISAM
  2. Benchmark Your Queries
  3. Check Your Indexes
  4. Use Invisible Indexes
  5. Use Prepared Statements
  6. Use Functional Indexes
  7. Run ANALYZE TABLE Regularly
  8. Backups – util.dumpInstance()

  1. Use The InnoDB Storage Engine not MyISAM
    • InnoDB is transactional, does point-in-time recovery very well, locks at the row level, and a whole of other great stuff with your data.
    • MyISAM is none of those. Many years ago it was the prime choice for websites but InnoDB has superseded it.
    • Use an ALTER TABLE <table_name> ENGINE=InnoDB; to covert table
Top 08 hack for Boost MySQL Performance
  1. Benchmark Your Queries
    • Save the query plan in FORMAT=TRADITIONAL and FORMAT=TREE along with the information on your data size for future reference and the output from SHOW CREATE TABLE. 
    • When the inevitable cries of ‘the database is slow’ rise there is now a basis from which to do your assessment.
    • Without a reference, there is no way to determine what, if anything, has changed.
Top 08 hack for Boost MySQL Performance
  1. Check Your Indexes
    • MySQL Workbench will report on unused indexes. 
    • Unused indexes take up memory and need to be maintained by the server.
    • If you are not using an index then get rid of it to free up resources.
    • In addition, Workbench can tell you what queries are running without indexes.
Top 08 hack for Boost MySQL Performance
  1. Use Invisible Indexes
    • But before you get rid of that unused index, please check the server uptime.
    • If the system is fairly recently rebooted then the system may not have built up the statistics on that index as it runs only once a week or so.
    • When in doubt make that index invisible so that the optimizer is unaware of it but it can quickly be made visible just in case it is needed for a monthly or quarterly report.
Top 08 hack for Boost MySQL Performance
  1. Use Prepared Statements
    • You do not need to send the entire query over each time along with the new data. Prepared statements allow you to send over just the needed data, which can be big wins in bandwidth and time.
    • Many MySQL connectors for the various programming languages also help reduce the occurrences of SQL Injection problems as it will check the type of the parameters being passed so that the ‘Little Bobby Drop Tables’ can not happen.
Top 08 hack for Boost MySQL Performance
  1. Use Functional Indexes
    • Functional indexes are a handy way to use a calculation on values to speed search.
    • Need to be able to search for rows where you want the combination of the cost of goods sold and the shipping are a certain amount or the birth month of a customer is February?
Top 08 hack for Boost MySQL Performance
  1. Run ANALYZE TABLE Regularly
    • ANALYZE TABLE does an analysis of the keys in the index of a table and updates the statistics that the optimizer uses when determining the optimal query plan.
    • If the statistics are out of date it is very much like using out-of-data directions for traveling between cities – you will get there eventually but there may be a better way.
Top 08 hack for Boost MySQL Performance
  1. Backups – util.dumpInstance()
    • With MySQLSH’s util.dumpInstance() and util.dumpSchema() there are fast and reliable ways to make backups of your data. 
    • You can move a copy from the MySQL Data Service cloud to on-premises and vice versa.
    • Also, save those binary logs if you need to do precise point-in-time recovery
Top 08 hack for Boost MySQL Performance

Follow Our Laravel.Tips account on Instagram to get advanced tips on Laravel.

Comment (1)

  1. Steave
    23 December, 2022

    Useful

Leave a comment

Your email address will not be published. Required fields are marked *