Introduction of MySQL Log File
MySQL log file consists of records of actions that has been performed. MySQL server generates log files that are generated based on the actions performed. The log files are of different types: – error logs, ISAM log, general query log, update log, binary log, and slow query log.
- Error log File: It consists of all the records that has been encountered while running, starting or stopping mysql.
- ISAM Log File: It records all the changes that has been done to the ISAM tables.Used only for ISAM code debugging.
- General Query Log File: Contains information regarding the connections established and executed queries.
- Update Log File: Consists of information on all the changes that have been performed on data.
- Binary Log File: Which consists of all the modification that happened in the database
- Slow Query Log File: Stores all the details of the queries that took more than the “long_query_time” to execute.
Syntax of MySQL Log File
To check log location and settings the error log file in the shell:
mysql -se "SHOW VARIABLES" | grep -e log_error
To check log location and settings the general log file in the shell:
mysql -se "SHOW VARIABLES" | grep-e general_log
To check log location and settings the slow query log file in the shell:
mysql -se "SHOW VARIABLES" | grep -e slow_query_log
How does MySQL Log File Works?
Now let us see the error log that records the information about the errors encountered while running, starting or stopping mysqld. In windows, we have the path called “C:\ProgramData\MySQL\MySQL Server 8.0\Data” which consists of the error log as mentioned in the below screenshot. The type of the error log file is “err”. Below we have highlighted the same.
1. Error Log File
We can see the details of the error log file in the “config” file (my.ini) from the path
“C:\ProgramData\MySQL\MySQL Server 8.0”.
# Error Logging.
log-error="LAPTOP-78SCO0PP.err"
2. General Log File
Contains information regarding the connections established and executed queries.We can see the details of the general log file in the “config” file (my.ini) from the path “C:\ProgramData\MySQL\MySQL Server 8.0”.
# General and Slow logging.
log-output=FILE
general-log=0
general_log_file="LAPTOP-78SCO0PP.log"
Here the “general-log” =0 which means that the general log is not enabled. To enable we need to set the value to “general-log” =1.
3. Binary Log File
Show BINARY LOGS
Output:
Log_name | file_size | Encrypted |
LAPTOP-78SCO0PP-bin.000001 | 179 | No |
LAPTOP-78SCO0PP-bin.000002 | 2129912 | No |
mysqlbinlog log-file | mysql -h server_name
4. ISAM Log File
myisamlog processes contain the information of a MyISAM log file. In order to create the ISAM log file, we start the server with a –log-isam=log_file option. We just need to invoke myisamlog as below:
myisamlog [options] [file_name [tbl_name] …] Options can be of –c, -f, -F, -i, -o etc
5. Update Log File
The update log is replaced by the binary log. When the server is started, we mention the option with a file name as “–log-update[=file_name]” , mysqld writes a log file containing all SQL commands that update data like UPDATE or DELETE. It skips the UPDATE statements if the column value is already existing.
6. Slow Query Log File
Stores all the details of the queries that took more than the “long_query_time” to execute. Below is the query that shows the longest query executed.
We can see the details of the general log file in the “config” file (my.ini) from the path “C:\ProgramData\MySQL\MySQL Server 8.0”.
# Slow logging.
slow-query-log=1
slow_query_log_file="LAPTOP-78SCO0PP-slow.log"
long_query_time=10
7. Error Log File
Once we open the “error” log file we get the below data information: –
- InnoDB initialization has started.
- InnoDB initialization has ended.
- X Plugin ready for connections. Bind-address: ‘::’ port: 33060
- CA certificate ca.pem is self signed.
Timestamp | Thread | Type | Details |
2020-05-31T09:34:06 | 0 | [Warning] [MY-000081] [Server] | option ‘read_buffer_size’: unsigned value 5120 adjusted to 8192. |
2020-05-31T09:34:06 | 0 | [Warning] [MY-010915] [Server] | ‘NO_ZERO_DATE’, ‘NO_ZERO_IN_DATE’, and ‘ERROR_FOR_DIVISION_BY_ZERO’ sql modes should be used with strict mode. They will be merged with strict mode in a future release. |
2020-05-31T09:34:06 | 0 | [System] [MY-010116] [Server] | C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.20) starting as process 16316 |
2020-05-31T09:34:06 | 1 | [System] [MY-013576] [InnoDB] | InnoDB initialization has started. |
2020-05-31T09:34:13 | 1 | [System] [MY-013577] [InnoDB] | InnoDB initialization has ended. |
2020-05-31T09:34:14 | 0 | [System] [MY-011323] [Server] | X Plugin ready for connections. Bind-address: ‘::’ port: 33060 |
2020-05-31T09:34:17 | 0 | [Warning] [MY-010068] [Server] | CA certificate ca.pem is self signed. |
2020-05-31T09:34:17 | 0 | [System] [MY-010931] [Server] | C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: ready for connections. Version: ‘8.0.20’ socket: ” port: 3306 MySQL Community Server – GPL. |
2020-06-13T10:22:35 | 0 | [System] [MY-013105] [Server] | C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Normal shutdown. |
2020-06-13T10:23:20 | 0 | [System] [MY-010910] [Server] | C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Shutdown complete (mysqld 8.0.20) MySQL Community Server – GPL. |
2020-06-13T10:26:03 | 0 | [Warning] [MY-000081] [Server] | option ‘read_buffer_size’: unsigned value 5120 adjusted to 8192. |
2020-06-13T10:26:03 | 0 | [Warning] [MY-010915] [Server] | ‘NO_ZERO_DATE’, ‘NO_ZERO_IN_DATE’ and ‘ERROR_FOR_DIVISION_BY_ZERO’ sql modes should be used with strict mode. They will be merged with strict mode in a future release. |
2020-06-13T10:26:04 | 0 | [System] [MY-010116] [Server] | C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.20) starting as process 6292 |
2020-06-13T10:26:08 | 1 | [System] [MY-013576] [InnoDB] | InnoDB initialization has started. |
2020-06-13T10:26:18 | 1 | [System] [MY-013577] [InnoDB] | InnoDB initialization has ended. |
2020-06-13T10:26:25 | 0 | [System] [MY-011323] [Server] | X Plugin ready for connections. Bind-address: ‘::’ port: 33060 |
2020-06-13T10:26:29 | 0 | [Warning] [MY-010068] [Server] | CA certificate ca.pem is self signed. |
2020-06-13T10:26:30 | 0 | [System] [MY-010931] [Server] | C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: ready for connections. Version: ‘8.0.20’ socket: ” port: 3306 MySQL Community Server – GPL. |
8. Slow Query Log File
We can see the details of the general log file in the “config” file (my.ini) from the path “C:\ProgramData\MySQL\MySQL Server 8.0”.
Now let us see the slow query log file. Below are the details that we get from our database.
Start Time | User@Host | Query Time | Lock Time | Rows Sent | Rows Examined | Detail |
2020-06-06T12:48:49 | root[root] @ localhost [::1] Id: 32 | 11.770594 | 0.032157 | 174 | 960 | use sourcedb; SET timestamp=1591447717; SELECT * FROM information_schema.`TABLES` T, information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA WHERE CCSA.collation_name = T.table_collation LIMIT 0, 1000; |
Recommended Articles
This is a guide to MySQL Log File. Here we also discuss the introduction and how does mysql log file works along with examples and its code implementation. You may also have a look at the following articles to learn more –
12 Online Courses | 10 Hands-on Projects | 92+ Hours | Verifiable Certificate of Completion
4.5
View Course
Related Courses