[Start and view of]mysql log

Source: Internet
Author: User

MySQL has the following types of 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 refreshing the log, you can force mysqld to close and reopen the log file (or, in some cases, switch to a new log). Log refresh occurs when you execute a FLUSH logs statement or perform mysqladmin flush-logs or mysqladmin refresh
1. Error log
use the--log-error[=file_name] option to specify MYSQLD where the error log file will be saved. 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 perform a flush LOGS, the error log renames the suffix with-old and mysqld creates a new empty log file. (It will not be renamed if the--log-error option is not given).

If you do not specify--log-error, or (in Windows), if you use the--console option, the error is written to the standard error output stderr. Usually the standard output is your terminal.

2. General Query Log

Start it with the--log[=file_name] or the-l [file_name] option. If there is no value for the given file_name, 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 have been executed for more than long_query_time seconds. If the file_name value is not given, the default hostname is not The suffix is-slow.log. If a filename is given, but not an absolute pathname, the file is written to the data directory.

3. Update log

Use the--log-update[=file_name] option to start, not recommended.


Whether the log is enabled
Mysql>show variables like ' log_% ';
How to know the current log
Mysql> Show master status;
Show binary log Entries
Mysql> show master logs;
See binary log files with Mysqlbinlog
Shell>mysqlbinlog mail-bin.000001
or shell>mysqlbinlog mail-bin.000001 | tail
Specify the output location of the log in the configuration file.
The windows:windows configuration file is My.ini, usually under the MySQL installation directory or under C:\Windows.
The Linux:linux configuration file is my.cnf, usually 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


Under 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"


Turn on Slow query
Long_query_time = 2-refers to how long the SQL executed will be log down, here is 2 seconds
log-slow-queries=/usr/local/mysql/log/slowquery.log--Log the query back to a slower statement
Log-queries-not-using-indexes = nouseindex.log--literally, log down without using the indexed query
Log=mylog.log--Record all execution statements
Open MySQL log under windows:

Add these under [MySQL] (basically equal to the last side):

Log-error=

#Enter a name for the query log file. Otherwise a default name would be used.

#注: (written txt file editplus can be overloaded in time, but sometimes to be placed in the C-disk EditPlus can be loaded in time)

log= C:/mysql_query.log.txt

#Enter a name for the slow query log file. Otherwise a default name would be used.

log-slow-queries=

#Enter a name for the update log file. Otherwise a default name would be used.

Log-update=

#Enter a name for the binary log. Otherwise a default name would be used.

log-bin=

[Start and view of]mysql log

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.