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 clean up the disk space occupied by Docker

Docker takes up a lot of space. Whenever we run c...

Teach you to quickly build a web cluster project based on nginx

Table of contents 1. Project Environment 2. Proje...

A Brief Analysis on the Time Carrying Problem of MySQL

The default time type (datetime and timestamp) in...

Mysql some complex sql statements (query and delete duplicate rows)

1. Find duplicate rows SELECT * FROM blog_user_re...

Detailed explanation of Docker Volume permission management

Volume data volume is an important concept of Doc...

Tutorial on customizing rpm packages and building yum repositories for Centos

1 Keep the rpm package downloaded when yum instal...

What does the n after int(n) in MySQL mean?

You may already know that the length 1 of int(1) ...

HTML Table Tag Tutorial (47): Nested Tables

<br />In the page, typesetting is achieved b...

Detailed steps to use Arthas in a Docker container

What can Arthas do for you? Arthas is Alibaba'...

How to implement rounded corners with CSS3 using JS

I found an example when I was looking for a way t...

js to achieve image fade-in and fade-out effect

This article shares the specific code of js to ac...

Detailed explanation of the use of MySQL DML statements

Preface: In the previous article, we mainly intro...