Query MySQL Deadlock Logs Guide
To check the deadlock log in MySQL, follow these steps:
- Open the configuration file for MySQL (my.cnf or my.ini) and locate the following configuration items to edit:
- In the configuration for the MySQL server, set the output log to a file by enabling general logging and specifying the path to the log file.
- Set general-log to 1 to enable the general log, and specify general-log-file as the path for the log file.
- Restart the MySQL service for the configuration to take effect.
- Login to the MySQL server from the MySQL client.
- Execute the following command to query the deadlock logs:
- Display all global variables that relate to the general log.
- This command will display the value of general_log to ensure it is set to ON.
- Execute the following command to query the file path of the deadlock log:
- Display all global variables that match the pattern ‘general_log_file’.
- This command will display the value of general_log_file, which is the file path for the deadlock log.
- Open the deadlock log file with a text editor to view the recorded deadlock information.
Please be aware that enabling general logging in a production environment may have a certain impact on performance and cause log files to quickly grow in size. Therefore, it is recommended to disable general logging after querying deadlock logs and periodically clean up log files.