How to enable, disable, and view mysql logs

Source: Internet
Author: User

In mysql, logs are classified into error logs:-log-err query log:-log slow query log:-log-slow-queries update log:-log-update BINARY log: -Below I will introduce the methods for enabling, disabling, and viewing mysql logs.

1. Error Log
Use the-log-error [= file_name] Option to specify the location where mysqld saves the error log file. If the file_name value is not specified, mysqld uses the error log name host_name.err and writes the log file to the data directory. If you execute flush logs, the error log uses-old to rename the suffix and mysqld to create a new empty log file. (If the-log-error option is not provided, it will not be renamed ).

If-log-error is not specified, or (in Windows) if you use the-console option, the error is written to stderr. Standard output is usually your terminal.

2. General query logs
Use the-log [= file_name] Or-l [file_name] Option to start it. If the file_name value is not specified, the default name is host_name.log.

3. View logs

Check whether logs are enabled

The Code is as follows: Copy code
Mysql> show variables like 'Log _ % ';

View the current log activation status

The Code is as follows: Copy code
Mysql> show master status;

Display binary logs? ? /P>

The Code is as follows: Copy code
Mysql> show master logs;

4. Use mysqlbinlog to view binary log files

The Code is as follows: Copy code

Shell> mysqlbinlog/var/log/mysql/mysql-bin.000001
Or shell> mysqlbinlog/var/log/mysql/mysql-bin.000001 | tail
Or shell> mysqlbinlog/var/log/mysql/mysql-bin.000001-no-default

If an error occurs, the following error occurs:

The Code is as follows: Copy code
/Usr/local/mysql/bin/mysqlbinlog: unknown variable 'default-character-set = utf8 ′

This problem is caused by the addition

The Code is as follows: Copy code
Default-character-set = utf8

.

Mysqlbinlog does not support this setting. There are two solutions:

1. modify the configuration file my. cnf (my. ini in windows)
Comment out default-character-set = utf8
2. Add the parameter-no-default during execution.

The Code is as follows: Copy code
Shell & gt; mysqlbinlog-no-default/var/log/mysql/mysql-bin.000001 | tail


You can export the log content to the. SQL file for ease of viewing.

The Code is as follows: Copy code

Mysqlbinlog ../log-bin/logbin.000001-> a. SQL

C:/Program Files/MySQL Server 5.0/bin>
C:/Program Files/MySQL Server 5.0/bin> mysqlbinlog ../log_bin_ljs/logbin.000001
/*! 40019 SET @ session. max_insert_delayed_threads = 0 */;
/*! 50003 SET @ OLD_COMPLETION_TYPE = @ COMPLETION_TYPE, COMPLETION_TYPE = 0 */;
DELIMITER /*! */;
# At 4
#100830 16:30:55 server id 1 end_log_pos 98 Start: binlog v 4, server v 5.0.
67-community-nt-log created 100830 16:30:55 at startup
# Warning: this binlog was not closed properly. Most probably mysqld crashed wri
Ting it.
ROLLBACK /*! */;
DELIMITER;
# End of log file
ROLLBACK/* added by mysqlbinlog */;
/*! 50003 SET COMPLETION_TYPE = @ OLD_COMPLETION_TYPE */;

C:/Program Files/MySQL Server 5.0/bin>

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.