mysql_slow_query
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| mysql_slow_query [2016/02/01 16:42] – luke7858 | mysql_slow_query [2024/05/23 07:26] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | === Slow Query Logs === | ||
| + | Checking the slow query logs via mysql prompt. | ||
| + | \\ | ||
| + | \\Note: You CAN enable the slow query logging on runtime. A mysql restart will flush the changes made via runtime. If you wish for persistence then add it to the /etc/my.cnf file: | ||
| + | <sxh bash> | ||
| + | mysql> SHOW GLOBAL VARIABLES LIKE ' | ||
| + | +---------------------+-------------------------------+ | ||
| + | | Variable_name | ||
| + | +---------------------+-------------------------------+ | ||
| + | | slow_query_log | ||
| + | | slow_query_log_file | / | ||
| + | +---------------------+-------------------------------+ | ||
| + | </ | ||
| + | Set the logs to another path: | ||
| + | <sxh bash> | ||
| + | mysql> SET GLOBAL slow_query_log_file = '/ | ||
| + | </ | ||
| + | <sxh bash> | ||
| + | mysql> SET GLOBAL slow_query_log = ' | ||
| + | </ | ||
| + | \\ | ||
| + | Via the command line: | ||
| + | \\ | ||
| + | \\ | ||
| You can check to see if slow query logging is currently enabled. The following command assumes you have configured .my.cnf file: | You can check to see if slow query logging is currently enabled. The following command assumes you have configured .my.cnf file: | ||
| <sxh bash> | <sxh bash> | ||
| - | show full variables like " | + | show variables like " |
| </ | </ | ||
| Or you can run the following from the command line: | Or you can run the following from the command line: | ||
| Line 24: | Line 48: | ||
| </ | </ | ||
| \\ | \\ | ||
| + | === How many slow queries? === | ||
| You can also use the following command to view if you currently have any slow queries (if logging has been enabled): | You can also use the following command to view if you currently have any slow queries (if logging has been enabled): | ||
| + | <sxh bash> | ||
| + | show status like ' | ||
| + | </ | ||
| + | Or from the command line: | ||
| <sxh bash> | <sxh bash> | ||
| mysql -e 'show status;' | mysql -e 'show status;' | ||
| Line 35: | Line 64: | ||
| \\ | \\ | ||
| ---------------------------------------------------------------- | ---------------------------------------------------------------- | ||
| + | === Configuring Slow Query logs === | ||
| \\ | \\ | ||
| - | There are now 2 options for configuring slow query logging. You can add the settings | + | There are 2 options for configuring slow query logs: |
| - | ===Option 1=== | + | \\ |
| + | \\ | ||
| + | -** Run time** - this will configure the slow query logs in the current runtime environment, | ||
| + | \\ | ||
| + | \\ | ||
| + | - **Permanent** - editing the /etc/my.cnf | ||
| + | \\ | ||
| + | \\ | ||
| + | **__NOTE__**: | ||
| + | \\ | ||
| + | \\ | ||
| + | === Run-time Configuration | ||
| \\ If run the following command it will set slow query logging without needing to restart mysql | \\ If run the following command it will set slow query logging without needing to restart mysql | ||
| <sxh bash> | <sxh bash> | ||
| Line 46: | Line 87: | ||
| mysql -e 'show variables;' | mysql -e 'show variables;' | ||
| </ | </ | ||
| + | \\ | ||
| - | ===Option 2 - .my.cnf === | + | === /etc/my.cnf |
| <sxh bash> | <sxh bash> | ||
| slow_query_log = 1 | slow_query_log = 1 | ||
| Line 53: | Line 95: | ||
| long_query_time = 10 | long_query_time = 10 | ||
| log_queries_not_using_indexes = 1 | log_queries_not_using_indexes = 1 | ||
| - | |||
| - | Change permissions so that mysqld can write to the specified log file. Giving write permissions to the ' | ||
| </ | </ | ||
| + | **Note**: Change permissions so that mysqld can write to the specified log file. Giving write permissions to the ' | ||
mysql_slow_query.1454344922.txt.gz · Last modified: 2024/05/23 07:26 (external edit)
