1. Enter the container login account
docker to view the running container
docker ps
Copy after login
![How to enable slow query log in docker mysql container](https://img.php.cn/upload/article/000/000/164/168542245238294.png)
##Enter the container:
docker exec -it dc8880c13fef /bin/bash
Copy after login
Enter the username and password Log in to mysql
mysql -u root -p
Copy after login
![How to enable slow query log in docker mysql container](https://img.php.cn/upload/article/000/000/164/168542245381819.png)
and then enter the password to log in
![How to enable slow query log in docker mysql container](https://img.php.cn/upload/article/000/000/164/168542245314300.png)
2. View slow log related information
The slow log is turned off by default.
show variables like ‘slow%’; (or use, see other bloggers say there will be version differences, then use double percent signs: show variables like ‘%slow %’;)
![How to enable slow query log in docker mysql container](https://img.php.cn/upload/article/000/000/164/168542245354124.png)
Turn on the slow log switch
set global slow_query_log = ON;
Copy after login
![How to enable slow query log in docker mysql container](https://img.php.cn/upload/article/000/000/164/168542245321483.png)
was successfully turned on.
You can modify the threshold for judging whether it is slow SQL. When the SQL execution exceeds the threshold, it will be recorded in the slow log log file.
![How to enable slow query log in docker mysql container](https://img.php.cn/upload/article/000/000/164/168542245321606.png)
After modification, test select query.
![How to enable slow query log in docker mysql container](https://img.php.cn/upload/article/000/000/164/168542245375207.png)
Here we can see that the sql is recorded in the slow log.
The above is the detailed content of How to enable slow query log in docker mysql container. For more information, please follow other related articles on the PHP Chinese website!