最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MySQL鎖情況查看命令

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

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

MySQL版本

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

模擬鎖產生

A會話加鎖

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會話插入數(shù)據(jù),造成鎖等待現(xiàn)象

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

這里介紹MySQL查看鎖的3個數(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:唯一事務id號,本次測試中是8552和8553
trx_state:當前事務的狀態(tài),本次測試中8553是LOCK WAIT 鎖等待狀態(tài)
trx_wait_started:事務開始等待時間,本次測試中為2022-12-14 16:52:29
trx_mysql_thread_id:線程id,與show full processlist中的id對應,本次測試中為22
trx_query:事務運行的SQL語句,本次測試為insert into t values(0,‘null’)
trx_operation_state:事務運行的狀態(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:請求鎖的事務id,本次測試為8553
blocking_trx_id:持有鎖的事務id,也就是造成鎖等待的事務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得知,會話id 20(事務id 8552),鎖住了ray.t表,鎖模式是行級鎖,會話id 22(事務id 8553)的insert操作需要等待會話20釋放鎖后才能執(zhí)行,因此出現(xiàn)了會話id 22(事務id 8553)hang住現(xiàn)象。

解決方法,殺會話

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

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

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

相關文章

  • MySQL8.0.32的安裝與配置超詳細圖文教程

    MySQL8.0.32的安裝與配置超詳細圖文教程

    這篇文章主要介紹了MySQL8.0.32的安裝與配置超詳細圖文教程,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-03-03
  • 在Windows環(huán)境下安裝MySQL 的教程圖解

    在Windows環(huán)境下安裝MySQL 的教程圖解

    這篇文章主要介紹了在Windows環(huán)境下安裝MySQL 的教程圖解,本文圖文并茂給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-07-07
  • MySQL全面瓦解之查詢的過濾條件詳解

    MySQL全面瓦解之查詢的過濾條件詳解

    這篇文章主要給打大家介紹了關于MySQL全面瓦解之查詢的過濾條件的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-11-11
  • MySQL?移動數(shù)據(jù)目錄后啟動失敗問題解決

    MySQL?移動數(shù)據(jù)目錄后啟動失敗問題解決

    由于安裝數(shù)據(jù)庫時將MySQL的數(shù)據(jù)目錄放在了根目錄下,現(xiàn)在存儲空間不足,遇到這個問題如何解決呢,下面小編給大家?guī)砹薽ysql移動數(shù)據(jù)目錄啟動失敗解決方法,感興趣的朋友一起看看吧
    2023-04-04
  • mysql 分頁優(yōu)化解析

    mysql 分頁優(yōu)化解析

    似乎討論分頁的人很少,難道大家都沉迷于limit m,n?在有索引的情況下,limit m,n速度足夠,可是在復雜條件搜索時,where somthing order by somefield+somefieldmysql會搜遍數(shù)據(jù)庫,找出“所有”符合條件的記錄,然后取出m,n條記錄。
    2008-04-04
  • 全面解析MySQL中的隔離級別

    全面解析MySQL中的隔離級別

    這篇文章主要介紹了MySQL中的隔離級別的相關資料,幫助大家更好的理解和使用MySQL,感興趣的朋友可以了解下。
    2021-01-01
  • MySQL找出未提交事務的SQL實例淺析

    MySQL找出未提交事務的SQL實例淺析

    這篇文章主要給大家介紹了關于MySQL找出未提交事務SQL的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-12-12
  • 關于mysql的時區(qū)問題

    關于mysql的時區(qū)問題

    這篇文章主要介紹了關于mysql的時區(qū)問題,具有很好的參考價值,希望對大家有所幫助,以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家,
    2023-11-11
  • mysql數(shù)據(jù)庫優(yōu)化總結(心得)

    mysql數(shù)據(jù)庫優(yōu)化總結(心得)

    本篇文章是對mysql數(shù)據(jù)庫優(yōu)化進行了詳細的總結與介紹,需要的朋友參考下
    2013-06-06
  • MySQL表聚合與聯(lián)合查詢的實現(xiàn)

    MySQL表聚合與聯(lián)合查詢的實現(xiàn)

    MySQL聚合與聯(lián)合查詢是數(shù)據(jù)庫查詢中常用的技術,它們能夠從多個數(shù)據(jù)源中提取和組合數(shù)據(jù),以獲得有用的信息和結果,本文就來介紹下MySQL聚合與聯(lián)合查詢,感興趣的可以了解一下
    2023-10-10

最新評論

藁城市| 通榆县| 弋阳县| 乡城县| 桦南县| 怀远县| 沙洋县| 伽师县| 文山县| 信宜市| 洮南市| 韶山市| 奈曼旗| 漳州市| 黔南| 休宁县| 雷州市| 梅州市| 景东| 肥城市| 巫山县| 白玉县| 诸城市| 大荔县| 靖江市| 习水县| 普宁市| 同仁县| 吉木萨尔县| 开江县| 民县| 康保县| 综艺| 翁牛特旗| 柳林县| 滁州市| 渝中区| 潢川县| 巴中市| 拉孜县| 巴彦县|