MySQL单实例常见故障汇总
- 故障现象一:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/data/mysql/mysql.sock'
- 故障现象二:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
- 故障现象三:在使用远程连接数据库时偶尔会发生远程连接数据库很慢的问题
- 故障现象四:Can't open file: 'xxx_forums.MYI'. (errno: 145)
- 故障现象五:ERROR 1129 (HY000): Host 'xxx.xxx.xxx.xxx' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
- 故障现象六:Too many connections
- 故障现象七:Warning: World-writable config file '/etc/my.cnf' is ignored ERROR! MySQL is running but PID file could not be found
- 故障现象八:InnoDB: Error: page 14178 log sequence number 29455369832,InnoDB: is in the future! Current system log sequence number
故障现象一:ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/data/mysql/mysql.sock’
报错:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/data/mysql/mysql.sock’
问题分析:
以上这种情况一般都是数据库未启动或者数据库端口被防火墙拦截导致
解决方法:
启动数据库或者防火墙开放数据库监听端口
故障现象二:ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)
报错:ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)
问题分析:
密码不正确或者没有权限访问
解决方法:
1)修改 my.cnf 主配置文件,在[mysqld]下添加 skip-grant-tables,重启数据库。最后修改密码命令如下:
mysql> use mysql;
mysql> update user set password=password("123456") where user="root";
再删除刚刚添加的 skip-grant-tables 参数,再重启数据库,使用新密码即可登录。
2)重新授权,命令如下:
mysql> grant all on *.* to 'root'@'mysql-server' identified by '123456';
故障现象三:在使用远程连接数据库时偶尔会发生远程连接数据库很慢的问题
在使用远程连接数据库时偶尔会发生远程连接数据库很慢的问题
问题分析:
如果 MySQL 主机查询 DNS 很慢或是有很多客户端主机时会导致连接很慢,由于开发机器是不能够连接外网的,所以 DNS 解析是不可能完成的,从而也就明白了为什么连接那么慢了。
解决方法:
修改 my.cnf 主配置文件,在[mysqld]下添加 skip-name-resolve,重启数据库可以解决。注意在以后授权里面不能再使用主机名授权。
故障现象四:Can’t open file: ‘xxx_forums.MYI’. (errno: 145)
报错:
Can’t open file: ‘xxx_forums.MYI’. (errno: 145)
问题分析:
1) 服务器非正常关机,数据库所在空间已满,或一些其它未知的原因,对数据库表造成了损坏。
2) 可能是操作系统下直接将数据库文件拷贝移动会因为文件的属组问题而产生这个错
误。
解决方法:
可以使用下面的两种方式修复数据表:(第一种方法仅适合独立主机用户)
1 ) 使用 myisamchk , MySQL 自带了专门用户数据表检查和修复的工具 — — myisamchk 。一般情况下只有在这个下面才能运行 myisamchk 命令。常用的修复命令为: myisamchk -r 数据文件目录/数据表名.MYI;
2)通过 phpMyAdmin 修复, phpMyAdmin 带有修复数据表的功能,进入到某一个表中后,点击“操作”,在下方的“表维护”中点击“修复表”即可。
注意:以上两种修复方式在执行前一定要备份数据库。修改文件的属组(仅适合独立主机用户):
复制数据库文件的过程中没有将数据库文件设置为 MySQL 运行的帐号可读写(一般适用于 Linux 和 FreeBSD 用户)。
故障现象五:ERROR 1129 (HY000): Host ‘xxx.xxx.xxx.xxx’ is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’
报错:
ERROR 1129 (HY000): Host ‘xxx.xxx.xxx.xxx’ is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’
问题分析:
由于 mysql 数据库的参数:max_connect_errors(系统默认 10) mysqld 已经得到了大量(max_connect_errors)的主机’hostname’的在中途被中断了的连接请求累计超过 10 次, 就再也无法连接上 mysqld 服务,同一个 ip 在短时间内产生太多中断的数据库连接而导致的阻塞(超过 mysql 数据库 max_connection_errors 的最大值)。
解决方法:
1) 使用 mysqladmin flush-hosts 命令清除缓存,命令执行方法如下:
mysqladmin -uroot -p -h 192.168.241.48 flush-hosts Enter password:
2) 修改 mysql 配置文件,在[mysqld]下面添加 max_connect_errors=1000
,然后重启MySQL。
故障现象六:Too many connections
客户端报错:Too many connections
问题分析:
连接数超出 Mysql 的最大连接限制。
解决方法:
1) 在 my.cnf 配置文件里面增加连接数,然后重启 MySQL 服务。
max_connections = 10000
2) 临时修改最大连接数,重启后不生效。需要在 my.cnf 里面修改配置文件,下次重启生效。
set GLOBAL max_connections=10000;
故障现象七:Warning: World-writable config file ‘/etc/my.cnf’ is ignored ERROR! MySQL is running but PID file could not be found
报错:
Warning: World-writable config file ‘/etc/my.cnf’ is ignored ERROR! MySQL is running but PID file could not be found
问题分析:
MySQL 的配置文件/etc/my.cnf 权限不对。
解决方法:
chmod 644 /et/my.cnf
故障现象八:InnoDB: Error: page 14178 log sequence number 29455369832,InnoDB: is in the future! Current system log sequence number
报错:
InnoDB: Error: page 14178 log sequence number 29455369832
InnoDB: is in the future! Current system log sequence number 29455369832
问题分析:
innodb 数据文件损坏。
解决方法:
修改 my.cnf 配置文件,在[mysqld]下添加 innodb_force_recovery=4, 启动数据库后备份数据文件,然后去掉该参数,利用备份文件恢复数据。