|
本帖最后由 jiawang 于 2023-9-13 08:23 编辑
当mysql 数据库发生死锁时, innodb status 里面会记录最后一次死锁的相关信息,但mysql 错误日志里面不会记录死锁相关信息,要想记录,启动 innodb_print_all_deadlocks 参数 。
当系统并发很高时,很多的线程等待同一个行锁,死锁检测可能会拖慢系统,这个时候关闭死锁检测可能更好innodb_deadlock_detect 5.7.15 版本才有)。让线程自动超时。
[root@sztech ~]# mysql -uroot -pWangjia
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.11 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql>
mysql> show VARIABLES LIKE '%innodb_print_all_deadlocks%';
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| innodb_print_all_deadlocks | OFF |
+----------------------------+-------+
1 row in set (0.00 sec)
mysql> set global innodb_print_all_deadlocks = ON;
Query OK, 0 rows affected (0.00 sec)
mysql> show VARIABLES LIKE '%innodb_print_all_deadlocks%';
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| innodb_print_all_deadlocks | ON |
+----------------------------+-------+
1 row in set (0.00 sec)
mysql>
如果输出结果中的Value列的值为ON,则表示日志已经被打印出来了。
- 死锁日志的默认路径是MySQL的数据目录下的ib_logfile文件中,其中为0至9的整数。我们可以通过以下方式查看死锁日志:
注意:
- 当前只是临时设置的,mysql 服务重启后,就off 了.......
- 想要永久生效需要在/etc/my.cnf 文件中修改或增加配置,注意增加的位置[mysqld] 的下面,否则无效;
innodb_print_all_deadlocks = ON
|
|