MySQL command lock status view

1、show processlist;

SHOW PROCESSLIST shows you which threads are running. You can also use the mysqladmin processlist statement to get this information. If you have the SUPER privilege, you can see all threads. Otherwise, you can only see your own threads (that is, associated with the MySQL account that you are using threads). If there is a thread in the update or insert a table, status of the process at this time as updating or sending data.
If you get "too many connections" error message and want to know what is happening, this statement is very useful. MySQL to retain an additional connection, allow the use of accounts that have the SUPER privilege, to ensure that the administrator can access and check the system (assuming that you do not have to give this permission for all users).

Most states correspond to very fast operation, as long as there is a thread to keep the same state for several seconds, then there might be a problem, should be checked. There are other states not listed in the above, but most of them just to see if there is an error that the server only need it.

2、show full processlist;

show processlist; only lists the top 100, if you want the full list, please use the show full processlist;

3、show open tables;

复制代码
mysql> show open tables from gongzhang_testx;
+-----------------+-----------------------------+--------+-------------+
| Database        | Table                       | In_use | Name_locked |
+-----------------+-----------------------------+--------+-------------+
| gongzhang_testx | gz_news                     |      0 |           0 |
| gongzhang_testx | gz_exam_sub_log             |      0 |           0 |
| gongzhang_testx | gz_chief_list_tmp           |      0 |           0 |
| gongzhang_testx | gz_comment                  |      0 |           0 |
| gongzhang_testx | gz_counsel                  |      0 |           0 |
| gongzhang_testx | gz_contract_jianli_pay      |      0 |           0 |
| gongzhang_testx | gz_focus                    |      0 |           0 |
| gongzhang_testx | gz_city                     |      0 |           0 |
| gongzhang_testx | gz_chief_goods_bss          |      0 |           0 |
复制代码

这条命令能够查看当前有那些表是打开的。In_use列表示有多少线程正在使用某张表,Name_locked表示表名是否被锁,这一般发生在Drop或Rename命令操作这张表时。所以这条命令不能帮助解答我们常见的问题:当前某张表是否有死锁,谁拥有表上的这个锁等。这个列表可能特别长,你的屏幕估计都装不下。我遇到过,滚动条翻到最上面还是显示不了第一行,所以可以考虑使用客户端软件查看。或者通过指定数据库来减少返回条数:show open tables from database;

4、show status like ‘%lock%’

查看服务器状态。

复制代码
mysql> show status like '%lock%';
+------------------------------------------+---------+
| Variable_name                            | Value   |
+------------------------------------------+---------+
| Com_lock_tables                          | 0       |
| Com_unlock_tables                        | 0       |
| Innodb_row_lock_current_waits            | 0       |
| Innodb_row_lock_time                     | 3946985 |
| Innodb_row_lock_time_avg                 | 1558    |
| Innodb_row_lock_time_max                 | 121788  |
| Innodb_row_lock_waits                    | 2532    |
| Key_blocks_not_flushed                   | 0       |
| Key_blocks_unused                        | 26716   |
| Key_blocks_used                          | 2660    |
| Performance_schema_locker_lost           | 0       |
| Performance_schema_rwlock_classes_lost   | 0       |
| Performance_schema_rwlock_instances_lost | 0       |
| Qcache_free_blocks                       | 27343   |
| Qcache_total_blocks                      | 61962   |
| Table_locks_immediate                    | 8504599 |
| Table_locks_waited                       | 2       |
+------------------------------------------+---------+
复制代码

 

5、show engine innodb status\G;

复制代码
*************************** 1. row ***************************
  Type: InnoDB
  Name: 
Status: 
=====================================
171221 12:09:47 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 47 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 339595 1_second, 339207 sleeps, 30987 10_second, 31236 background, 31233 flush
srv_master_thread log flush and writes: 343088
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 59209, signal count 73914
Mutex spin waits 243814, rounds 785599, OS waits 12909
RW-shared spins 58108, rounds 1500837, OS waits 40638
RW-excl spins 7233, rounds 212962, OS waits 4938
Spin rounds per wait: 3.22 mutex, 25.83 RW-shared, 29.44 RW-excl
------------
TRANSACTIONS
------------
Trx id counter 3502909
复制代码

MySQL 5.1之前的命令是:show innodbstatus\G;,MySQL 5.5使用上面命令即可查看innodb引擎的运行时信息。使用“\G” 可以改为纵向列出,查看更方便。

6、show variables like '%timeout%'

查看服务器配置参数

复制代码
mysql> show variables like '%timeout%';
+----------------------------+----------+
| Variable_name              | Value    |
+----------------------------+----------+
| connect_timeout            | 10       |
| delayed_insert_timeout     | 300      |
| innodb_lock_wait_timeout   | 120      |
| innodb_rollback_on_timeout | OFF      |
| interactive_timeout        | 28800    |
| lock_wait_timeout          | 31536000 |
| net_read_timeout           | 30       |
| net_write_timeout          | 60       |
| slave_net_timeout          | 3600     |
| wait_timeout               | 28800    |
+----------------------------+----------+
复制代码

7、SELECT * FROM information_schema.INNODB_TRX

查询 正在执行的事务:

8、SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;

查看正在锁的事务

9、SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;

查看等待锁的事务

Guess you like

Origin www.cnblogs.com/xingxia/p/mysql_lock.html