亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

MySQL鎖情況查看命令

 更新時(shí)間:2023年01月05日 11:09:02   作者:撓背小能手  
本文主要介紹了MySQL鎖情況查看命令,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

本文介紹如何在MySQL數(shù)據(jù)庫中分析鎖的情況及處理思路。

MySQL版本

mysql> select version();
+------------+
| version()  |
+------------+
| 5.7.38-log |
+------------+
1 row in set (0.01 sec)

模擬鎖產(chǎn)生

A會(huì)話加鎖

mysql> show create table t\G;
*************************** 1. row ***************************
? ? ? ?Table: t
Create Table: CREATE TABLE `t` (
? `id` int(11) NOT NULL,
? `name` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
? PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
1 row in set (0.00 sec)

ERROR:?
No query specified

mysql> select * from t;
+----+------+
| id | name |
+----+------+
| ?1 | a ? ?|
| ?2 | s ? ?|
| ?3 | c ? ?|
| ?4 | d ? ?|
| ?5 | e ? ?|
+----+------+
5 rows in set (0.00 sec)

mysql> begin;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from t where id<5 for update;
+----+------+
| id | name |
+----+------+
| ?1 | a ? ?|
| ?2 | s ? ?|
| ?3 | c ? ?|
| ?4 | d ? ?|
+----+------+
4 rows in set (0.00 sec)

B會(huì)話插入數(shù)據(jù),造成鎖等待現(xiàn)象

mysql> insert into t values(0,'null');

這里介紹MySQL查看鎖的3個(gè)數(shù)據(jù)字典表,分別是位于information_schema數(shù)據(jù)庫下的innodb_trx、innodb_lock_waits、innodb_locks三張表,查看步驟如下:

先看innodb_trx表

mysql> use information_schema;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select * from innodb_trx\G;
*************************** 1. row ***************************
? ? ? ? ? ? ? ? ? ? trx_id: 8553
? ? ? ? ? ? ? ? ?trx_state: LOCK WAIT
? ? ? ? ? ? ? ?trx_started: 2022-12-14 16:52:29
? ? ?trx_requested_lock_id: 8553:45:3:2
? ? ? ? ? trx_wait_started: 2022-12-14 16:52:29
? ? ? ? ? ? ? ? trx_weight: 2
? ? ? ?trx_mysql_thread_id: 22
? ? ? ? ? ? ? ? ?trx_query: insert into t values(0,'null')
? ? ? ?trx_operation_state: inserting
? ? ? ? ?trx_tables_in_use: 1
? ? ? ? ?trx_tables_locked: 1
? ? ? ? ? trx_lock_structs: 2
? ? ?trx_lock_memory_bytes: 1136
? ? ? ? ? ?trx_rows_locked: 1
? ? ? ? ?trx_rows_modified: 0
? ?trx_concurrency_tickets: 0
? ? ? ?trx_isolation_level: REPEATABLE READ
? ? ? ? ?trx_unique_checks: 1
? ? trx_foreign_key_checks: 1
trx_last_foreign_key_error: NULL
?trx_adaptive_hash_latched: 0
?trx_adaptive_hash_timeout: 0
? ? ? ? ? trx_is_read_only: 0
trx_autocommit_non_locking: 0
*************************** 2. row ***************************
? ? ? ? ? ? ? ? ? ? trx_id: 8552
? ? ? ? ? ? ? ? ?trx_state: RUNNING
? ? ? ? ? ? ? ?trx_started: 2022-12-14 16:51:39
? ? ?trx_requested_lock_id: NULL
? ? ? ? ? trx_wait_started: NULL
? ? ? ? ? ? ? ? trx_weight: 2
? ? ? ?trx_mysql_thread_id: 20
? ? ? ? ? ? ? ? ?trx_query: NULL
? ? ? ?trx_operation_state: NULL
? ? ? ? ?trx_tables_in_use: 0
? ? ? ? ?trx_tables_locked: 1
? ? ? ? ? trx_lock_structs: 2
? ? ?trx_lock_memory_bytes: 1136
? ? ? ? ? ?trx_rows_locked: 5
? ? ? ? ?trx_rows_modified: 0
? ?trx_concurrency_tickets: 0
? ? ? ?trx_isolation_level: REPEATABLE READ
? ? ? ? ?trx_unique_checks: 1
? ? trx_foreign_key_checks: 1
trx_last_foreign_key_error: NULL
?trx_adaptive_hash_latched: 0
?trx_adaptive_hash_timeout: 0
? ? ? ? ? trx_is_read_only: 0
trx_autocommit_non_locking: 0
2 rows in set (0.00 sec)

ERROR:?
No query specified

mysql> show full processlist;
+----+--------+-----------+--------------------+---------+------+----------+--------------------------------+
| Id | User ? | Host ? ? ?| db ? ? ? ? ? ? ? ? | Command | Time | State ? ?| Info ? ? ? ? ? ? ? ? ? ? ? ? ? |
+----+--------+-----------+--------------------+---------+------+----------+--------------------------------+
| 20 | root ? | localhost | ray ? ? ? ? ? ? ? ?| Sleep ? | ?132 | ? ? ? ? ?| NULL ? ? ? ? ? ? ? ? ? ? ? ? ? |
| 22 | raybak | localhost | ray ? ? ? ? ? ? ? ?| Query ? | ? 82 | update ? | insert into t values(0,'null') |
| 24 | root ? | localhost | information_schema | Query ? | ? ?0 | starting | show full processlist ? ? ? ? ?|
+----+--------+-----------+--------------------+---------+------+----------+--------------------------------+
3 rows in set (0.00 sec)

trx_id:唯一事務(wù)id號(hào),本次測試中是8552和8553
trx_state:當(dāng)前事務(wù)的狀態(tài),本次測試中8553是LOCK WAIT 鎖等待狀態(tài)
trx_wait_started:事務(wù)開始等待時(shí)間,本次測試中為2022-12-14 16:52:29
trx_mysql_thread_id:線程id,與show full processlist中的id對(duì)應(yīng),本次測試中為22
trx_query:事務(wù)運(yùn)行的SQL語句,本次測試為insert into t values(0,‘null’)
trx_operation_state:事務(wù)運(yùn)行的狀態(tài),本次測試為inserting

再看innodb_lock_waits表

mysql> select * from innodb_lock_waits\G;
*************************** 1. row ***************************
requesting_trx_id: 8553
requested_lock_id: 8553:45:3:2
  blocking_trx_id: 8552
 blocking_lock_id: 8552:45:3:2
1 row in set, 1 warning (0.00 sec)

requesting_trx_id:請(qǐng)求鎖的事務(wù)id,本次測試為8553
blocking_trx_id:持有鎖的事務(wù)id,也就是造成鎖等待的事務(wù)id,本次測試為8552

再看innodb_locks表

mysql> select * from innodb_locks\G;
*************************** 1. row ***************************
? ? lock_id: 8553:45:3:2
lock_trx_id: 8553
? lock_mode: X,GAP
? lock_type: RECORD
?lock_table: `ray`.`t`
?lock_index: PRIMARY
?lock_space: 45
? lock_page: 3
? ?lock_rec: 2
? lock_data: 1
*************************** 2. row ***************************
? ? lock_id: 8552:45:3:2
lock_trx_id: 8552
? lock_mode: X
? lock_type: RECORD
?lock_table: `ray`.`t`
?lock_index: PRIMARY
?lock_space: 45
? lock_page: 3
? ?lock_rec: 2
? lock_data: 1
2 rows in set, 1 warning (0.00 sec)

ERROR:?
No query specified

綜合三張表查詢和show prcess fulllist得知,會(huì)話id 20(事務(wù)id 8552),鎖住了ray.t表,鎖模式是行級(jí)鎖,會(huì)話id 22(事務(wù)id 8553)的insert操作需要等待會(huì)話20釋放鎖后才能執(zhí)行,因此出現(xiàn)了會(huì)話id 22(事務(wù)id 8553)hang住現(xiàn)象。

解決方法,殺會(huì)話

mysql> kill 20;
Query OK, 0 rows affected (0.00 sec)

當(dāng)然,殺會(huì)話也可以通過pt-kill工具更方便,在后續(xù)文章會(huì)對(duì)pt-kill工具做詳細(xì)介紹

到此這篇關(guān)于MySQL鎖情況查看命令的文章就介紹到這了,更多相關(guān)MySQL鎖情況查看內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 記一次Mysql不走日期字段索引的原因小結(jié)

    記一次Mysql不走日期字段索引的原因小結(jié)

    本文主要介紹了記一次Mysql不走日期字段索引的原因,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • 在windows10上安裝mysql詳細(xì)圖文教程

    在windows10上安裝mysql詳細(xì)圖文教程

    這篇文章主要介紹了在windows10上安裝mysql詳細(xì)圖文教程,本文介紹的非常詳細(xì),具有參考借鑒價(jià)值,感興趣的朋友一起看看吧
    2016-09-09
  • 詳解MySQL查看執(zhí)行慢的SQL語句(慢查詢)

    詳解MySQL查看執(zhí)行慢的SQL語句(慢查詢)

    查看執(zhí)行慢的SQL語句,需要先開啟慢查詢?nèi)罩?,MySQL的慢查詢?nèi)罩?,記錄在MySQL中響應(yīng)時(shí)間超過閥值的語句(具體指運(yùn)行時(shí)間超過long_query_time值的SQL,本文給大家介紹MySQL查看執(zhí)行慢的SQL語句,感興趣的朋友跟隨小編一起看看吧
    2024-03-03
  • MySQL中的datediff()方法和timestampdiff()方法的應(yīng)用示例小結(jié)

    MySQL中的datediff()方法和timestampdiff()方法的應(yīng)用示例小結(jié)

    在MySQL中,DATEDIFF()函數(shù)和TIMESTAMPDIFF()函數(shù)用于計(jì)算日期和時(shí)間之間的差異,TIMESTAMPDIFF()函數(shù)返回的結(jié)果是整數(shù),但你可以通過在計(jì)算過程中使用適當(dāng)?shù)某▉慝@得所需的小數(shù)部分,本文介紹MySQL中的datediff()方法和timestampdiff()方法的應(yīng)用,感興趣的朋友一起看看吧
    2023-12-12
  • MySQL查詢時(shí)指定使用索引的實(shí)現(xiàn)

    MySQL查詢時(shí)指定使用索引的實(shí)現(xiàn)

    在MySQL中,可以通過指定查詢使用的索引來提高查詢性能和優(yōu)化查詢執(zhí)行計(jì)劃,本文就來介紹一下MySQL查詢時(shí)指定使用索引的實(shí)現(xiàn),感興趣的可以了解一下
    2023-11-11
  • 根據(jù)status信息對(duì)MySQL服務(wù)器進(jìn)行優(yōu)化

    根據(jù)status信息對(duì)MySQL服務(wù)器進(jìn)行優(yōu)化

    網(wǎng)上有很多的文章教怎么配置MySQL服務(wù)器,但考慮到服務(wù)器硬件配置的不同,具體應(yīng)用的差別,那些文章的做法只能作為初步設(shè)置參考,我們需要根據(jù)自己的情況進(jìn)行配置優(yōu)化,好的做法是MySQL服務(wù)器穩(wěn)定運(yùn)行了一段時(shí)間后運(yùn)行,根據(jù)服務(wù)器的”狀態(tài)”進(jìn)行優(yōu)化。
    2011-09-09
  • mysql存儲(chǔ)過程詳解

    mysql存儲(chǔ)過程詳解

    我們常用的操作數(shù)據(jù)庫語言SQL語句在執(zhí)行的時(shí)候需要要先編譯,然后執(zhí)行,而存儲(chǔ)過程(Stored Procedure)是一組為了完成特定功能的SQL語句集,經(jīng)編譯后存儲(chǔ)在數(shù)據(jù)庫中,用戶通過指定存儲(chǔ)過程的名字并給定參數(shù)(如果該存儲(chǔ)過程帶有參數(shù))來調(diào)用執(zhí)行它
    2012-07-07
  • mysql prompt的用法詳解

    mysql prompt的用法詳解

    本篇文章是對(duì)mysql中prompt的用法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • mysql decimal類型判斷是否為0

    mysql decimal類型判斷是否為0

    在MySQL中,DECIMAL是一種用于存儲(chǔ)精確小數(shù)的數(shù)據(jù)類型,本文主要介紹了mysql decimal類型判斷是否為0,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-02-02
  • mysql如何通過當(dāng)前排序字段獲取相鄰數(shù)據(jù)項(xiàng)

    mysql如何通過當(dāng)前排序字段獲取相鄰數(shù)據(jù)項(xiàng)

    這篇文章主要介紹了mysql如何通過當(dāng)前排序字段獲取相鄰數(shù)據(jù)項(xiàng),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05

最新評(píng)論