今天查看mycat的mycat.log发现文件很大,很诧异,打开一看,全部都是错误:
register err java.nio.channels.ClosedChannelException
发现有个mysql节点链接失败,于是远程mysql -hxx.xxx.xxx.xx -u -p也是报错Host ‘hostname’ is blocked because of many connection errors; unblock with 'mysqladmi.
mysql环境是5.7.
查找原因如下:
MySQL服务器已经从某个host接收了大量中途终止的连接,于是决定终止继续接收来自该host的连接。允许最大的连接错误数为max_connect_errors,通过show variables like max%命令可以查询,一般为10。
可能是数据库密码错误(检查配置文件正常,所以排除他人修改),也可能是网络因素。
解决办法:
一、提高允许的max_connection_errors数量(治标不治本):
1.进入Mysql数据库查看max_connection_errors:
show variables like ‘%max_connect_errors%’;
2.修改max_connect_errors的数量为1000:
set global max_connect_errors = 1000;
3.查看是否修改成功:
show variables like ‘%max_connect_errors%’;
也可以修改mysql配置文件my.cnf max_connect_errors = 1000;不过要重启mysql。
二、使用mysqladmin flush-hosts 命令清理一下hosts文件(不知道mysqladmin在哪个目录下可以使用命令查找:whereis mysqladmin);
1.在查找到的目录下使用命令修改:/usr/bin/mysqladmin flush-hosts -h192.168.1.1 -P3308 -uroot -prootpwd;
配置有master/slave主从数据库的要把主库和从库都修改一遍的
2.也可以在数据库中进行,进入mysql:
mysql -h127.0.0.1 -u -p
flush hosts;