16.13 MySQL常见问题

主库异常,从库手动切换为主库方案

1.登录从服务器,确认从服务器已经完成所有同步操作:

mysql> stop slave io_thread  
mysql> show processlist 
直到看到状态都为:xxx has read all relay log 表示更新都执行完毕

2.停止从服务器slave服务:

mysql> stop slave

3.将从服务器切换为主服务器:

mysql> reset master

完成切换

4.授权内网其他机器有写入等权限(如果没有权限的话)

mysql> SELECT Host,User FROM mysql.user;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.%' IDENTIFIED BY '123456'  WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;

5.修改其他机器hosts或应用内连接

# vi /etc/hosts
192.168.1.106 db-001

Mysql常见的几个错误问题及解决方法:

mysql DNS反解:skip-name-resolve

错误日志有类似警告:

  1. 120119 16:26:04 [Warning] IP address '192.168.1.10' could not be resolved: Name or service not known

  2. 120119 16:26:04 [Warning] IP address '192.168.1.14' could not be resolved: Name or service not known

  3. 120119 16:26:04 [Warning] IP address '192.168.1.17' could not be resolved: Name or service not known

通过show processlist发现大量类似如下的连接:

  1. |592|unauthenticated user|192.168.1.10:35320|NULL|Connect| |login|NULL|

  2. |593|unauthenticated user|192.168.1.14:35321|NULL|Connect| |login|NULL|

  3. |594|unauthenticated user|192.168.1.17:35322|NULL|Connect| |login|NULL|

    skip-name-resolve 参数的作用:不再进行反解析(ip不反解成域名),这样可以加快数据库的反应时间。 修改配置文件添加并需要重启:

一键安装mysql脚本

Last updated

Was this helpful?