mysql

Slow query - MySQL

What is slow query? https://dev.mysql.com/doc/refman/8.0/en/slow-query-log.html The definition “slow query” is “SQL statements that take more than long_query_time seconds to execute and require at least min_examined_row_limit rows to be examined”. Configure Check current status SHOW VARIABLES LIKE "slow_query_log"; SHOW VARIABLES LIKE "slow_query_time"; SHOW VARIABLES LIKE "slow_query_log_file"; Enable to log slow queries Logging slow queries which take more than 10 seconds. SET GLOBAL slow_query_log = 'ON'; SET GLOBAL long_query_time = 10; SET GLOBAL slow_query_log_file = '/path/filename'; A sample line in the log file:

MySQL snippets

Create a temporary Docker MySQL container docker run \ --detach \ --name=mysqltest \ --env="MYSQL_ROOT_PASSWORD=FoOPass123" \ --publish 3306:3306 \ mysql PhpMyAdmin (Docker) Before run this command, check the network of MySQL container with docker inspect mytestest. docker run --name myadmin -d -e PMA_HOST=172.17.0.2 -e PMA_PORTS=3306 -p 8080:80 phpmyadmin Open the browser and go http://localhost:8080. The user is MySQL user (root and FoOPass123 in my case). MySQL workbench (Docker, I don’t use this way) I found this image.

Install MySQL on macOS

Install Install MySQL in macOS with the installer Use official installer. MySQL - Official Download page: https://dev.mysql.com/downloads/mysql/ Initial password of the root user The root means the MySQL root user, not your macOS You should take a memo your password of root user (not Linux system super user.) For CLI After running installer, add the PATH to ~/.zshrc (or your shell. Check with $echo SHELL). alias mysql=/usr/local/mysql/bin/mysql alias mysqladmin=/usr/local/mysql/bin/mysqladmin Check the version mysql --version /usr/local/mysql/bin/mysql Ver 8.