I'm using MySQL Server version: 5.5.8-log MySQL Community Server (GPL)
I want to log queries which are not using INDEX and is slow too !
I'm copying here my my.ini settings.
[mysqld]
port=3306
log = "E:/wamp/logs/genquery.log"
log_slow_queries
long_query_time = 1
slow_query_log = 1
slow_query_log_file = "E:/wamp/logs/slowquery.log"
what change i need to do ?
The Benefits and Drawbacks of Using Indexes in MySQLIndexes consume disk space. Indexes degrade the performance of INSERT, UPDATE and DELETE queries – when data is updated, the index needs to be updated together with it. MySQL does not protect you from using multiple types of indexes at the same time.
In addition to a1ex07's answer you can use the shell command mk-query-digest to output a report of your running queries without using the log. Useful to fast detect unindexed queries.
The USE INDEX ( index_list ) hint tells MySQL to use only one of the named indexes to find rows in the table. The alternative syntax IGNORE INDEX ( index_list ) tells MySQL to not use some particular index or indexes.
log_queries_not_using_indexes : This tells MySQL to also log any queries that run without indexes to the /var/log/mysql-slow. log file. This setting isn't required for the slow query log to function, but it can be helpful for spotting inefficient queries.
log_queries_not_using_indexes =1 //(or Yes)
(From mysql)
Maybe useful for Linux user. (Testet: Ubuntu 16.04)
Get root in terminal and edit mysql configuration
su
vim /etc/mysql/conf.d/mysql.cnf
[mysqld]
slow_query_log=1
slow_query_log_file=/var/log/mysql/slow-query.log
long_query_time=1
log_queries_not_using_indexes=1
Add log file and restart mysql server
touch /var/log/mysql/slow-query.log
chown mysql:adm /var/log/mysql/slow-query.log
chmod 640 slow-query.log
service mysql restart
Test slow logging with SQL queries
/* Activate query log - Maybe useful to show errors (not necessary) */
SET GLOBAL SLOW_QUERY_LOG=ON;
/* Check if slow query log is working */
SELECT SLEEP(2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With