mysql8定位被鎖語句

2021-09-10 07:28:22 字數 3061 閱讀 2691

首先檢視系統鎖情況,下面這條語句可以看到持有鎖的執行緒以及執行緒id,這裡需要注意下,session_id也就是show processlist查詢出來的鏈結id,在這個表裡表現為pid,同時該錶也記錄了trx_id,最後還給出了解決方案也就是如何kill持有鎖的程序。

mysql> select * from sys.`innodb_lock_waits` \g

*************************** 1. row ***************************

wait_started: 2019-01-28 14:27:03

wait_age: 00:00:03

wait_age_secs: 3

locked_table: `test`.`t`

locked_table_schema: test

locked_table_name: t

locked_table_partition: null

locked_table_subpartition: null

locked_index: gen_clust_index

locked_type: record

waiting_trx_id: 19758723

waiting_trx_started: 2019-01-28 14:27:03

waiting_trx_age: 00:00:03

waiting_trx_rows_locked: 1

waiting_trx_rows_modified: 0

waiting_pid: 4202

waiting_query: update t set id=8

waiting_lock_id: 19758723:4998:4:2

waiting_lock_mode: x

blocking_trx_id: 19748728

blocking_pid: 4200

blocking_query: null

blocking_lock_id: 19748728:4998:4:2

blocking_lock_mode: x

blocking_trx_started: 2019-01-28 10:58:27

blocking_trx_age: 03:28:39

blocking_trx_rows_locked: 2

blocking_trx_rows_modified: 1

sql_kill_blocking_query: kill query 4200

sql_kill_blocking_connection: kill 4200

1 row in set (0.02 sec

檢視當前被鎖的語句

##等待鎖的語句

檢視持有鎖的語句可以通過如下方式

##持有鎖的語句

檢視未提交事務的會話狀態,並查詢未提交的sql

select 

p.id as conn_id,

p.user as login_user,

p.host as login_host,

p.db as database_name,

p.time as trx_sleep_seconds,

time_to_sec(timediff(now(), t.trx_started)) as trx_open_seconds,

t.trx_started,

t.trx_isolation_level,

t.trx_tables_locked,

t.trx_rows_locked,

t.trx_state,

p.command as process_state

from

`information_schema`.`innodb_trx` t

inner join `information_schema`.`processlist` p

on t.trx_mysql_thread_id = p.id

where t.trx_state = 'running'

and p.command = 'sleep'

and p.time > 1

order by t.trx_started asc ;

select * from performance_schema.events_statements_history where thread_id=(

select processlist_id from performance_schema.threads where processlist_id=127);

mysql8問題 mysql8中的問題

only full group by 對於group by聚合操作,如果在 select 中的列,沒有在 group by 現,那麼這個sql是不合法的,因為列不在group by從句中。no auto value on zero 該值影響自增長列的插入。預設設定下,插入0或null代表生成下乙個自...

mysql8建立不了使用者 mysql8建立使用者

假如是mysql8版本的話,使用 grant all privileges to 使用者 localhost identified by 自定義密碼 會報錯,因為要先建立使用者再進行賦權,不能同時進行 建立使用者 create user 使用者名稱 localhost identified by 密...

mysql 8 命令 Mysql8常用命令

1 安裝 移除原來的mysql服務 mysqld remove mysql mysqld install 2 初始化 mysqld initialize 3 啟動 net start mysql 4 登陸 mysql u root p 5 修改密碼 mysqld shared memory skip...