Linux/windows platform monitors the SQL statements executed by MySQL

Source: Internet
Author: User
Tags chmod

Linux Platform

Monitoring the SQL statements executed by MySQL

In order to do well with the development of performance and functional testing, easy to monitor the execution of the SQL statement,

You can add the following in/etc/mysqld:

Log =/usr/local/mysql/var21005/mysql.log
You can use:
Tail-f Mysql.log www.111cn.net
to monitor.

If you need to monitor a slow query, you can add the following:

Log-slow-queries =/usr/local/mysql/var21005/slowquery.log
Long_query_time = 1


Windows platform

Example of a Windows platform:

Modify My.ini, add log row under Mysqld,

[Mysqld]
Log = "D:/tmp/mysql_log/mysql_log.sql"

Then, when you restart MySQL, you can see in real time the statement that the MYQL server is currently executing.


In addition to the above method can also use slow log monitoring MySQL execution state

Enable MySQL log-slow-queries (slow query record).

In the Linux environment to find the My.cnf file (generally in/etc/mysql/), and then you may find that the file can not be saved after the modification, because you do not have the appropriate permissions, you can see from the properties of the file owner is root, then the first to open it as root:

sudo nautilus/etc/mysql

Then open the My.cnf file and find the [mysqld] tab and add the following:

log-slow-queries=/path/slow.log– Slow Log save path, the file itself new
long_query_time=2– query for more than 2 seconds
log-queries-not-using-indexes– record queries that do not use indexes

Save, close. Then, if you restart MySQL, you'll get the hint: world-writable config file ' etc my.cnf ' is ignored

Then you need to run this code again:

chmod 644/etc/my.cnf–644 says Rw-r–r–www.111cn.net

And then restart the service OK.

But note: Log-slow-queries=/path/slow.log for the slow query log storage place, and this directory to have the MySQL running account can write permissions, the directory is generally set to MySQL data storage directory.

I do this: first use the root user into the MySQL data storage directory (typically/var/lib/mysql), create a new Slow.log file (root users can be guaranteed to create new, and then run chmod 644). Then change the owner and the group of the file:

Chown the name of the MySQL running account (you can see the owner and group of other files in the same folder) + decimal + Group name (method with user name)/path/slow.log

Or:

Chown the name of the MySQL run account (you can see the owner and group of other files in the same folder)/path/slow.log

CHGRP group name (method with user name)/path/slow.log

This ensures that MySQL can write logs to Slow.log.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.