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

MySQL master-slave data is inconsistent, prompt: Slave_SQL_Running: No solution

This article uses an example to describe the solu...

Detailed explanation of how to create MySql scheduled tasks in navicat

Detailed explanation of creating MySql scheduled ...

Solution to CSS flex-basis text overflow problem

The insignificant flex-basis has caused a lot of ...

Specific use of Docker anonymous mount and named mount

Table of contents Data volume Anonymous and named...

Prototype and prototype chain prototype and proto details

Table of contents 1. Prototype 2. Prototype chain...

Example of implementing TikTok text shaking effect with CSS

In daily development, front-end students often ar...

Study notes to write the first program of Vue

Table of contents 1. Write an HTML, the first Vue...

Configure selenium environment based on linux and implement operation

1. Using Selenium in Linux 1. Install Chrome Inst...

VUE+Canvas implements the game of God of Wealth receiving ingots

Welcome to the previous canvas game series: 《VUE ...

In-depth analysis of the slow query problem of MySQL Sending data

Through an example, I shared with you the solutio...

HTML framework_Powernode Java Academy

1. Framework A browser document window can only d...

Detailed explanation of writing multiple conditions of CSS: not

The :not pseudo-class selector can filter element...