↑ ↓ select, Enter open, Esc close

Enable the slow query log at runtime

Caution: This command changes the system. Understand what it does before you run it.

Adjust the values, the command updates live
root@server
mysql -e 'SET GLOBAL slow_query_log = 1; SET GLOBAL long_query_time = 2; SHOW VARIABLES LIKE "slow_query_log_file";'

Enables the slow query log and sets the threshold above which queries are logged. The path of the log file is printed afterwards. The setting lasts until the next restart of the database service, and new connections pick up the threshold.

Note: Turn it off with SET GLOBAL slow_query_log = 0;. To make it permanent, add it to /etc/mysql/mariadb.conf.d/50-server.cnf. With a low threshold, the log grows quickly.

Also searched as

  • find slow mysql queries
  • enable slow query log
  • database slowing down website

Related one-liners

All in MySQL and MariaDB

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.