mysql零碎笔记
mysql5.7启动参数状态变量手册
http://dev.mysql.com/doc/refman/5.7/en/mysqld-option-tables.html
参数配置不正确或者不起作用
- mysql每一个版本的参数都会有些变化,不要想当然的认为一些参数起作用,设置参数前一定要翻一下对应版本的手册。
- 如果是手工安装mysql,检查是否有系统自带的mysql包。先卸载,并删除/etc/my.cnf配置文件,再检查自己的配置。
最大连接错误
mysql5.7.9中max_connect_errors参数默认为100,如果连接错误次数超过100,mysql会禁止访ip登录。比方说业务程序中配置的错误的用户名密码,应该不停地登录重试,一直报错,达到100次就会被拉黑,事后改为正确的用户名密码也无法登录。解决办法如下
mysqladmin flush-hosts -uroot -p
或者登录mysql服务器,执行
FLUSH HOSTS;
到达最大连接
查看Connection_errors_max_connections连接变量是否大于0,如果比较大,连接不够用,超过参数max_connections配置
show variables like '%max_connections%';
show status like '%Connection_errors_max_connections%';
最大使用的并发连接数
show status like '%Max_used_connections%';
最大并发连接发生时间
show status like '%Max_used_connections_time%';
名称解析导致mysql登录缓存
vim my.cnf
在[mysqld]这段中添加
skip-host-cache
skip-name-resolve
清空业务表
清空test数据库下,不是以sys和demo开头的表
use information_schema;
SELECT CONCAT('truncate table ' , TABLE_NAME , ';') as sqlstr FROM TABLES where TABLE_SCHEMA='test'
and (TABLE_NAME not like 'sys%' and TABLE_NAME not like 'demo%');
导表某些业务表
导出test库下所有以sys开头的表到sys.sql文件
mysqldump --opt -uroot -p test $(mysql -uroot -p -D billyex -Bse "SHOW TABLES LIKE 'sys%'") > sys.sql
备份单个库testdb
mysqldump -uroot -p --opt --databases testdb> testdb_`date "+%Y%m%d%H%M%S"`.sql
恢复数据据
mysql -uroot -p testdb< testdb.sql
流式结果集
如果stmt.setFetchSize(Integer.MIN_VALUE);使用流式结果集
参见mysql驱动中com.mysql.jdbc.StatementImpl类的createStreamingResultSet方法
/**
* We only stream result sets when they are forward-only, read-only, and the
* fetch size has been set to Integer.MIN_VALUE
*
* @return true if this result set should be streamed row at-a-time, rather
* than read all at once.
*/
protected boolean createStreamingResultSet() {
try {
synchronized (checkClosed().getConnectionMutex()) {
return ((this.resultSetType == java.sql.ResultSet.TYPE_FORWARD_ONLY) && (this.resultSetConcurrency == java.sql.ResultSet.CONCUR_READ_ONLY) && (this.fetchSize == Integer.MIN_VALUE));
}
} catch (SQLException e) {
// we can't break the interface, having this be no-op in case of error is ok
return false;
}
}