Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log QUERIES not using INDEX - MySQL

Tags:

mysql

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 ?

like image 843
Sourav Avatar asked Jun 21 '11 16:06

Sourav


People also ask

Why index is not being used in MySQL?

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.

How do I find unindexed queries in MySQL without log?

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.

Does MySQL use index for in query?

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.

What is Log_queries_not_using_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.


2 Answers

log_queries_not_using_indexes =1 //(or Yes) (From mysql)

like image 94
a1ex07 Avatar answered Oct 20 '22 13:10

a1ex07


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);
like image 9
Cyb10101 Avatar answered Oct 20 '22 13:10

Cyb10101