全站最帅😎
发布于 2022-11-02 / 898 阅读
1
1

MySQL命令大全

-- 查看连接超时时间
show variables like 'wait_timeout'

-- 查看数据页大小
show variables like 'innodb_page_size'

-- 查看mysql 版本
select version() from dual;

-- 查看 buffer pool 大小
show variables like 'innodb_buffer_pool_size'

-- 查看change buffer大小,数值为buffer size的占比
-- change buffer 因为减少了随机磁盘访问,所以对更新性能的提升十分明显
show variables like 'innodb_change_buffer_max_size'

-- 查看redo log相关配置
show variables like 'innodb_log_%'

-- 查看单个redo log文件大小
show variables like 'innodb_log_file_size'

-- 查看redo log文件数量
show variables like 'innodb_log_files_in_group'

-- redo log刷盘参数
-- 0 :设置为 0 的时候,表示每次事务提交时不进行刷盘操作
-- 1 :设置为 1 的时候,表示每次事务提交时都将进行刷盘操作(默认值)
-- 2 :设置为 2 的时候,表示每次事务提交时都只把 redo log buffer 内容写入操作系统的 page cache,由操作系统来控制 fsync 的时机
show variables like 'innodb_flush_log_at_trx_commit'

-- 查看binlog cache 大小
show variables like 'binlog_cache_size'

-- 查看binlog的刷盘时机
-- 0:表示每次提交事务都只 write 到操作系统的 page cache,由系统自行判断什么时候执行 fsync。
-- 1:表示每次提交事务都会执行 fsync
-- >1:表示每次提交事务都 write,但累积N个事务后才 fsync(如果出现io瓶颈,可以这样设置)
show variables like 'sync_binlog'

-- 查看数据库事务隔离级别
show variables like 'transaction_isolation';

-- 查找持续时间超过 60s 的事务
select * from information_schema.innodb_trx where TIME_TO_SEC(timediff(now(),trx_started))>60

-- 锁相关
-- 全局读锁
Flush tables with read lock

-- 启动一致性视图,该语句执行之后就开启事务
START TRANSACTION  WITH CONSISTENT SNAPSHOT;

-- 启动事务,一致性视图是在执行第一个快照读语句时创建的
begin / start transaction

-- 锁超时时间
show variables like 'innodb_lock_wait_timeout';

-- 查看脏页比例
select VARIABLE_VALUE into @a from performance_schema.global_status where VARIABLE_NAME = 'Innodb_buffer_pool_pages_dirty'; 
select VARIABLE_VALUE into @b from performance_schema.global_status where VARIABLE_NAME = 'Innodb_buffer_pool_pages_total'; 
select @a/@b;

评论