MySQL records the executed SQL statements

Source: Internet
Author: User

During program debugging, one way is to start from the first line, which is very hard (for example, the program source files are too many or compiled or encrypted ). The other method is to check from the back. The last write is the DB, so we start to push forward from the DB, so we need to grasp what SQL syntax the program executes.

The tracing method we used previously was to use tcpdump or wireshark to listen to the 3306 port. This is too bitter and I will not talk about it more ~

MySQL can be used in several ways. Add/etc/mysql/my. cnf (debian) to one of your favorite methods and restart mysql:

First: query the SQL Syntax of Slow query:

Log_slow_queries =/var/log/mysql/mysql-slow.log.

Long_query_time = 2 (the SQL syntax is recorded for more than 2 seconds. It is also a method to set a short value to record the exception .)

Type 2: Set binlog for MySQL Replication:

Log_bin =/var/log/mysql/mysql-bin.log (this file should be viewed using mysqlbinlog)

Mysql records all INSERT/UPDATE/DELETE syntaxes here (but the syntax may be different from what you think). This is the log file to be written to SLAVE.

Method 3: We recommend that you record all the commands executed by MySQL:

Log =/tmp/mysql. log

After restart mysql, You can see tail-f/tmp/mysql. log! :)

Supplement: the earliest method is mysqldump, and then mysqldump and diff after execution, but this method is abandoned after DB> 1G.

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.