MySQL 5.1 5.2 5.5 5.6 5.7/MySQL8.0-(MariaDB8.0)
-- DB
-- select @@version ; -- 查看 数据库版本信息 -- show engines; -- 查看 数据库可用的存储引擎和默认引擎。 -- show table status; -- 查看 数据库表类型和表的最新更新时间。 -- show privileges; -- 查看 数据库所支持的不同权限。 -- show variables like 'port' ; 查看 数据库(数据 日志 缓存)存储路径 -- show variables like '%max_connections%'; -- 查看 连接池最大连接数 -- show variables like '%dir%'; -- 查看 数据库(数据 日志 缓存)存储路径 -- select * from mysql.user ; -- 查看 数据库用户 -- user grant information -- 查看 数据库授权 -- show grants for 用户名@localhost;-- 查看 数据库指定用户授权信息 -- show databases;-- 查看 所有数据库 --Tables -- show tables; -- 查看 数据库表 -- select * from information_schema.columns where table_schema='数据库名' and table_name='数据库表名' ; -- 查看 数据库表结构信息 -- show index from zt_user; -- 查看 数据库表索引 -- explain select * from zt_user; -- * 索引全扫描类型 -- * ALL 全表扫描,没有优化,最慢的方式 -- * index 索引全扫描,其次慢的方式 -- * range 索引范围扫描,常用语<,<=,>=,between等操作 -- * ref 使用非唯一索引扫描或唯一索引前缀扫描,返回单条记录,常出现在关联查询中 -- * eq_ref 类似ref,区别在于使用的是唯一索引,使用主键的关联查询 -- * const/system 单条记录,系统会把匹配行中的其他列作为常数处理,如主键或唯一索引查询,system是const的特殊情况 -- * null MySQL不访问任何表或索引,直接返回结果
--事务
SELECT * FROM information_schema.processlist ;-- mysql 查看查看连接的客户端
-- 查看事务记录:
select * from information_schema.INNODB_TRX;
select * from information_schema.processlist where id = [trx_mysql_thread_id]
--事务
SELECT * FROM information_schema.processlist ;-- mysql 查看查看连接的客户端
-- 查看事务记录:
select * from information_schema.INNODB_TRX;
select * from information_schema.processlist where id = [trx_mysql_thread_id]
-- 存储过程 select name from mysql.proc where db='数据库名'; select routine_name from information_schema.routines where routine_schema='数据库名'; show procedure status where db='数据库名'; SELECT * FROM information_schema.Routines WHERE ROUTINE_NAME=存储过程名;
-- 触发器 SELECT * FROM information_schema.`TRIGGERS` --日志 show variables like 'general_log%' -- log -- set global general_log = ON show variables like 'log_output'; -- 慢查询日志 --事件 SELECT * FROM information_schema.EVENTS; --记录 select * from mysql.general_log; -- 事务隔离等级(RU RC etc.) 默认REPEATABLE-READ select @@tx_isolation;