The MySQL slow query log can be very helpful when dealing with database optimization, and today you will practice analyzing it!
In this task, you will work with a ShopDB database, which has 2 tables:
Products1that uses the InnoDB database engine;Products2that uses the MyISAM database engine.
- Install and configure a MySQL database server on a Virtual Machine.
- Fork this repository.
In this task, you will need to analyze the MySQL slow query log and compare the read operation performance for 2 database engines: InnoDB and MyISAM:
-
Connect to your database server virtual machine via SSH and enable a slow query log by updating the MySQL configuration file. Set the configuration option
long_query_timeto0so you will see all queries in the slow query log. After the config file update, restart the MySQL service usingsystemctl. -
Run the
task.sqlscript, which creates the database and populates test data on your database server. -
Close database connection from the MySQL Workbench.
-
Connect to your server using MySQL client on your virtual machine and run 2 sample queries:
- first one:
select * from Products1 where Name = "AwersomeProduct42"; - second one:
select * from Products2 where Name = "AwersomeProduct42";
- first one:
💡 Run each query at least 10 times.
If you run queries from MySQL Workbench, there will be a lot of additional queries in the log which it will be hard to analyze, so make sure to use a terminal client (you already have one installed on the virtual machine, where the database server is running).
-
Analyse the slow query log and identify the query which works slower (on average) than the other one.
-
Edit the
task.sqlfile: remove the code for the table creation and data creation, which is used by the "slow" query. Submit your solution for a review.