查看正在被锁定的的表

show OPEN TABLES where In_use > 0;

in_use:多少个线程在使用

name_locked:是否被锁

查询哪些线程正在运行

show processlist;

最关键的就是state列

查看正在锁的事务

SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;

查看等待锁的事务

SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;


在事务当中,Tansaction isolation level 为REPEATABLE READ(可重读)情况,锁的操作

mysql> select k from t where id=1 lock in share mode; #乐观锁(s锁,共享锁),可读

mysql> select k from t where id=1 for update; #悲观锁,排他锁

悲观锁:在读取数据时锁住那几行,其他对这几行的更新需要等到悲观锁结束时才能继续 。

乐观所:读取数据时不锁,更新时检查是否数据已经被更新过,如果是则取消当前更新,一般在悲观锁的等待时间过长而不能接受时我们才会选择乐观锁。

注:for update 仅适用于InnoDB,并且必须开启事务,在begin与commit之间才生效。

查Mysql服务器上的版本

mysql> select version();

查看表的引擎

mysql> show create table t;

或者

mysql> show table status from 库名 where name='t' \G

查mysql当前默认的存储引擎:

mysql> show variables like '%storage_engine%';


查整个MySQL实例里面存储引擎为MyISAM的表

mysql> select table_catalog

,table_schema

,table_name

,engine

from information_schema.tables

where engine='MyISAM';

查询MyDB数据库里面存储引擎为MyISAM的表

mysql> select table_catalog

,table_schema

,table_name

,engine

from information_schema.tables

where table_schema='MyDB' and engine='MyISAM';

相关文章:

  • 2022-02-26
  • 2022-12-23
  • 2021-07-14
  • 2021-10-01
猜你喜欢
  • 2022-12-23
  • 2021-12-30
  • 2021-10-04
  • 2021-09-22
相关资源
相似解决方案