从docker进入mysql容器的指令: docker exec -it mysql /bin/bash
进入之后如何进入mysql: mysql -uroot -proot
进入mysql之后展示所有的库: show databases;
进入指定的库: Use 加库名
表锁: lock table 加表名 + read or write (设置锁的格式)
解锁: unlock tables
查看所有表的锁状态: show open tables
表锁分析: show status like 'table%';
看mysql当前事务的隔离级别: show variables like 'tx_isolation';
看行锁分析:show status like 'innodb_row_lock%';
查询是否锁表:show OPEN TABLES where In_use > 0;
查询进程:show processlist
kill进程: kill+进程id
查看正在锁的事务: SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;
查看等待锁的事务:SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;
查看慢查询日志是否开启: show variables like '%slow_query_log%';
开启慢查询日志: set global slow_query_log=1;
查看多少秒算慢: show variables like 'long_query_time%';
设置慢时间: set global long_query_time=? (?是指你需要的时间);
show variables like 'log_bin_trust_function_creators';
set global log_bin_trust_function_creators=1;
delimiter +符号 设置sql结束的符号
查看是否开启profile:show variables like 'profiling';
开启:set profiling=on;
看每个sql语句运行的时间,并可以看到query-id: show profiele;
通过query-id可以看这条sql语句运行内部的时间: show profile cpu,block io for query +query-id;
如果出现诊断出现以下的东西就要注意了!
开启全局查询日志 set global general_log=1;
记录日志文件路径 general_log_file=/path/logfile;
输出格式: log_output=file;
以表的形式输出 set global log_output='TABLE';
此后你所编写的sql语句都会记录到这张表 用这个语句查看 select * from mysql.genneral_log;