Enable and disable MySQL logs

Source: Internet
Author: User

After mysql is installed, you can start the bin-log function to record database data operation records and recover data when necessary. mysql logs are divided into the following types:

Error log:-log-err

Query log:-log

Slow query log:-log-slow-queries

Update log:-log-update

Binary log:-log-bin

Check whether logs are enabled:

Mysql> show variables like 'Log _ % ';

To start the mysql binary log, follow these steps:

1. Configure mysql's my. ini and add it under [mysqld]

Log-bin = C:/Program Files/MySQL Server 5.0/log-bin/logbin. log

The above is the directory for storing mysql binary logs, which can be specified at will. I created a log-bin folder under the root directory of mysql installation as the directory for storing binary log files, pay attention to the following two points when specifying a path:

1. The directory name cannot contain spaces. For example, the "aa bb" folder is not allowed. In this way, an error is reported when accessing logs;

2 when specifying a directory, you must use *. the end of the log, that is, the folder level cannot be specified, such as the logbin I wrote above. log. At this time, the log file name is logbin.000001 logbin.000002... Otherwise, no log files will be generated.

Ii. mysql. after ini is modified, save and restart the mysql service. logbin.000001 and logbin will be generated in the C:/Program Files/MySQL Server 5.0/log-bin directory after restart. index files.

3. View binary files

In the doscommand line, go to the mysql installation directory, that is, C:/Program Files/MySQL Server 5.0, go to the bin/directory, and run the mysqlbinlog command to view the log:

Mysqlbinlog .. \ log-bin \ logbin.000001

It is worth noting that the following path problem occurs. You can use absolute or relative paths for paths, and the separator can be "/" or "\". the two delimiters can be recognized normally, and the folder name in the path cannot contain spaces. This test has been performed (if it is an absolute path C: /Program Files/MySQL Server 5.0/log-bin/logbin.000001 will report an error and the file cannot be found because "C:/Program Files" contains spaces)

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

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>

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.