连接数设置
| Command-Line Format | —max-connections=# |
|---|---|
| System Variable | max_connections |
| Scope | Global |
| Dynamic | Yes |
| Type | Integer |
| Default Value | 151 |
| Minimum Value | 1 |
| Maximum Value | 100000 |
show status like 'Threads%';show global status like 'Thread%';show variables like '%max_connection%'; -- 查看最大连接数set global max_connections=1000;-- 重新设置最大连接数(默认151)
超时设置
show variables like '%timeout%';show global variables like '%timeout';-- interactive_timeout和wait_timeout需要同时设置set global interactive_timeout = 288000;set global wait_timeout = 288000;
存储引擎查看
-- 所有引擎show engines;-- 当前使用的存储引擎show variables like '%storage_engine%';
存储目录
show variables like '%datadir%';
慢查询设置
show variables like '%slow_query_log%';show global variables like '%slow_query_log%';show variables like '%long_query_time%';show global variables like '%long_query_time%';-- 会话生效set global slow_query_log=1;set global long_query_time=10;
永久生效:
[mysqld]slow_query_log = 1 # 慢查询sql日志设置long_query_time = 10 # 慢查询时间;超过1秒则为慢查询slow_query_log_file = /home/mysql/3306/log/slow.log
验证:
select sleep(11);show global status like '%Slow_queries%';
诊断SQL
show variables like '%profiling%';set profiling=on;show profiles;show profile for query 1;show profile cpu,block io for query 1;
临时表空间控制
show global variables like 'tmpdir';set @@global.innodb_tmpdir='/database/mysql/data/3306/';
日志查看
查看日志开启状态show variables like 'log_%';查看所有binlog日志列表show master logs;查看最新一个binlog日志的编号名称,及其最后一个操作事件结束点show master status;刷新log日志,立刻产生一个新编号的binlog日志文件,跟重启一个效果flush logs;清空所有binlog日志reset master;
索引信息查询
-- 查看索引信息show index from ${tableName};
说明:
- Table:表的名称。
- Non_unique:如果索引不能包括重复词,则为0。如果可以,则为1。
- Key_name:索引的名称。
- Seq_in_index:索引中的列序列号,从1开始。
- Column_name:列名称。
- Collation:列以什么方式存储在索引中。在MySQLSHOW INDEX语法中,有值’A’(升序)或NULL(无分类)。
- Cardinality:索引中唯一值的数目的估计值。通过运行ANALYZE TABLE或myisamchk -a可以更新。基数根据被存储为整数的统计数据来计数,所以即使对于小型表,该值也没有必要是精确的。基数越大,当进行联合时,MySQL使用该索引的机会就越大。
- Sub_part:如果列只是被部分地编入索引,则为被编入索引的字符的数目。如果整列被编入索引,则为NULL。
- Packed:指示关键字如何被压缩。如果没有被压缩,则为NULL。
- Null:如果列含有NULL,则含有YES。如果没有,则为空。
- Index_type:存储索引数据结构方法(BTREE, FULLTEXT, HASH, RTREE)。
元信息查询
selecttable_schema as 数据库名 ,table_name as 表名,column_name as 列名,column_type as 数据类型,data_type as 字段类型,character_maximum_length as 长度,is_nullable as 是否为空,column_default as 默认值,column_comment as 备注from information_schema.columnswhere table_schema ='你的数据库名字'and table_name = '你的表名字'limit 5;
参考
简书:怎么查看mysql的binlog日志存放的位置
https://www.jianshu.com/p/346de5089ccd
