MySQL log settings and viewing methods

MySQL log settings and viewing methods

MySQL has the following logs:
Error log: -log-err
Query log: -log
Slow query log: -log-slow-queries
Update log: -log-update
Binary log: –log-bin
By default, all logs are created in the mysqld data directory. By flushing the log, you can force mysqld to close and reopen the log file (or switch to a new log in some cases). A log flush occurs when you execute a FLUSH LOGS statement or when you execute mysqladmin flush-logs or mysqladmin refresh.

1. Error log <br /> Use the --log-error[=file_name] option to specify the location where mysqld saves the error log file. If no file_name value is given, mysqld uses the error log name host_name.err and writes the log file in the data directory. If you execute FLUSH LOGS, the error log is renamed with the suffix -old and mysqld creates a new, empty log file. (If the --log-error option is not given, no renaming will occur.)
If you do not specify --log-error, or (on Windows) if you use the --console option, errors are written to standard error output, stderr. Usually standard output is your terminal.

2. General query log
Start it with the --log[=file_name] or -l [file_name] option. If no value for file_name is given, the default name is host_name.log.

3. Slow query log
When started with the --log-slow-queries[=file_name] option, mysqld writes a log file containing all SQL statements that took longer than long_query_time seconds to execute. If no file_name value is given, it defaults to the host name with the suffix -slow.log. If a file name is given, but not an absolute path name, the file is written to the data directory.

3. Changelog
Starting with the --log-update[=file_name] option is not recommended.

Is logging enabled?
mysql>show variables like 'log_%';
How to know the current log
mysql> show master status;
Displays the number of binary logs
mysql> show master logs;
View binary log files using mysqlbinlog
shell>mysqlbinlog mail-bin.000001
Or shell>mysqlbinlog mail-bin.000001 | tail

Specify the log output location in the configuration file.
Windows: The Windows configuration file is my.ini, which is usually in the MySQL installation directory or c:\Windows.
Linux: The Linux configuration file is my.cnf, which is usually located in /etc.
Under linux:
Sql code
# Enter in [mysqld]
#log
log-error=/usr/local/mysql/log/error.log
log=/usr/local/mysql/log/mysql.log
long_query_time=2
log-slow-queries= /usr/local/mysql/log/slowquery.log
# Enter #log in [mysqld]
log-error=/usr/local/mysql/log/error.log
log=/usr/local/mysql/log/mysql.log
long_query_time=2
log-slow-queries= /usr/local/mysql/log/slowquery.log


Windows:
Sql code
# Enter in [mysqld]
#log
log-error="E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/error.log"
log="E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/mysql.log"
long_query_time=2
log-slow-queries="E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/slowquery.log"
# Enter #log in [mysqld]
log-error="E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/error.log"
log="E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/mysql.log"
long_query_time=2
log-slow-queries="E:/PROGRA~1/EASYPH~1.0B1/mysql/logs/slowquery.log"


Enable slow query
long_query_time = 2 -- refers to how long the SQL will be logged after it is executed. Here it is 2 seconds
log-slow-queries= /usr/local/mysql/log/slowquery.log --Record the statements that return slower queries
log-queries-not-using-indexes = nouseindex.log -- logs queries that do not use indexes
log=mylog.log --Record all executed statements
Enable mysql log under windows:
Add these under [mysql] (basically adding them at the end):
log-error=
#Enter a name for the query log file. Otherwise a default name will be used.
#Note: (Written as a txt file editplus can be reloaded in time, but sometimes it needs to be placed in the C drive editplus can be reloaded in time)
log= c:/mysql_query.log.txt
#Enter a name for the slow query log file. Otherwise a default name will be used.
log-slow-queries=
#Enter a name for the update log file. Otherwise a default name will be used.
log-update=
#Enter a name for the binary log. Otherwise a default name will be used.
log-bin=

You may also be interested in:
  • How to enable slow query logging in MySQL
  • mysql enable slow query how to enable mysql slow query logging
  • MySQL log file details
  • MySQL Series 11 Logging

<<:  Nginx uses Lua+Redis to dynamically block IP

>>:  Solve the problem that the element DateTimePicker+vue pop-up box only displays hours

Recommend

How to change the system language of centos7 to simplified Chinese

illustrate When you install the system yourself, ...

Beginners learn some HTML tags (3)

Beginners who are exposed to HTML learn some HTML...

How to write object and param to play flash in firefox

Copy code The code is as follows: <object clas...

Method and introduction of table index definition in MySQL

Overview An index is a table of correspondence be...

CSS solves the misalignment problem of inline-block

No more nonsense, post code HTML part <div cla...

How to disable web page styles using Firefox's web developer

Prerequisite: The web developer plugin has been in...

WeChat applet implements simple calculator function

WeChat applet: Simple calculator, for your refere...

Tutorial diagram of installing zabbix2.4 under centos6.5

The fixed IP address of the centos-DVD1 version s...

A brief summary of basic web page performance optimization rules

Some optimization rules for browser web pages Pag...

Detailed explanation of the solution to docker-compose being too slow

There is only one solution, that is to change the...

JS array deduplication details

Table of contents 1 Test Cases 2 JS array dedupli...

Tutorial on installing mysql5.7.18 on windows10

This tutorial shares the installation and configu...

Usage of mysql timestamp

Preface: Timestamp fields are often used in MySQL...

Solve the scroll-view line break problem of WeChat applet

Today, when I was writing a small program, I used...