Some common statements for viewing transactions and locks in the database Check transaction waiting status:SELECT r.trx_id waiting_trx_id, r.trx_mysql_thread_id waiting_thread, r.trx_query waiting_query, b.trx_id blocking_trx_id, b.trx_mysql_thread_id blocking_thread, b.trx_query blocking_query FROM information_schema.innodb_lock_waits w INNER JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id INNER JOIN information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id; View more specific transaction waiting status:SELECT b.trx_state, e.state, e.time, d.state AS block_state, d.time AS block_time, a.requesting_trx_id, a.requested_lock_id, b.trx_query, b.trx_mysql_thread_id, a.blocking_trx_id, a.blocking_lock_id, c.trx_query AS block_trx_query, c.trx_mysql_thread_id AS block_trx_mysql_tread_id FROM information_schema.INNODB_LOCK_WAITS a LEFT JOIN information_schema.INNODB_TRX b ON a.requesting_trx_id = b.trx_id LEFT JOIN information_schema.INNODB_TRX c ON a.blocking_trx_id = c.trx_id LEFT JOIN information_schema.PROCESSLIST d ON c.trx_mysql_thread_id = d.id LEFT JOIN information_schema.PROCESSLIST e ON b.trx_mysql_thread_id = e.id ORDER BY a.requesting_trx_id; View unclosed transactions:–MySQL 5.6 SELECT a.trx_id, a.trx_state, a.trx_started, a.trx_query, b.ID, b.USER, b.DB, b.COMMAND, b.TIME, b.STATE, b.INFO, c.PROCESSLIST_USER, c.PROCESSLIST_HOST, c.PROCESSLIST_DB, d.SQL_TEXT FROM information_schema.INNODB_TRX a LEFT JOIN information_schema.PROCESSLIST b ON a.trx_mysql_thread_id = b.id AND b.COMMAND = 'Sleep' LEFT JOIN PERFORMANCE_SCHEMA.threads c ON b.id = c.PROCESSLIST_ID LEFT JOIN PERFORMANCE_SCHEMA.events_statements_current d ON d.THREAD_ID = c.THREAD_ID; –MySQL 5.5 SELECT a.trx_id, a.trx_state, a.trx_started, a.trx_query, b.ID, b. USER, b. HOST, b.DB, b.COMMAND, b.TIME, b.STATE, b.INFO FROM information_schema.INNODB_TRX a LEFT JOIN information_schema.PROCESSLIST b ON a.trx_mysql_thread_id = b.id WHERE b.COMMAND = 'Sleep'; View transactions that have not been closed for a period of time:SELECT trx_id, trx_started, trx_mysql_thread_id FROM INFORMATION_SCHEMA.INNODB_TRX WHERE trx_started < date_sub(now(), INTERVAL 1 MINUTE) AND trx_operation_state IS NULL AND trx_query IS NULL; Supplement: MySQL lock status view command 1 show processlist;SHOW PROCESSLIST shows which threads are running. You can also use the mysqladmin processlist statement to obtain this information. If you have the SUPER privilege, you can see all threads. Otherwise, you can see only your own threads (that is, threads associated with the MySQL account you are using). If a thread is updating or inserting a table, the status of the process is updating or sending data. This statement is useful if you get a "too many connections" error message and want to understand what is happening. MySQL reserves an extra connection for use by accounts with the SUPER privilege to ensure that administrators can always connect and examine the system (assuming you do not grant this privilege to all users).
Most states correspond to very fast operations. If a thread remains in the same state for several seconds, there may be a problem and it needs to be checked. There are other statuses not listed above, but most of them are only useful to see if there are any errors with the server. 2 show full processlist;show processlist; only the first 100 items are listed. If you want to list all items, please use show full processlist; 3 show open tables;This command can check which tables are currently open. The In_use column indicates how many threads are using a table, and Name_locked indicates whether the table name is locked, which usually occurs when the Drop or Rename command operates on this table. Therefore, this command cannot help answer our common questions: whether a certain table is currently deadlocked, who owns the lock on the table, etc. show open tables from database; 4 show status like '%lock%'Check the server status. 5 show engine innodb status\G;The command before MySQL 5.1 is: show innodbstatus\G;. In MySQL 5.5, you can use the above command to view the runtime information of the innodb engine. 6 show variables like '%timeout%';View server configuration parameters. The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me. You may also be interested in:
|
<<: HTML table markup tutorial (40): Dark border color attribute of the header BORDERCOLORDARK
>>: Example of implementing the skeleton screen of WeChat applet
This article shares the specific code of JavaScri...
1. Preparation before installation 1. Download th...
There are various environmental and configuration...
I believe that everyone needs to copy and paste d...
Preface This control will have a watermark at the...
Preview of revised version This article was writt...
The scope of css is global. As the project gets b...
This article is an integrated article on how to c...
Table of contents Preface 1. Trigger Overview 2. ...
The operating environment of this tutorial: Windo...
The vue part is as follows: <template> <...
background: In MySQL, if there is a limited level...
1: Download MySql Official website download addre...
Table of contents 1. DOM Diff 2. Add key attribut...
Table of contents fold (reduce) Using for...of Us...