遇到这些问题,网上很多解决方案,一搜就有。在这我简单总结下
第一个:ERROR 2003 (HY000): Can't connect to MySQL server on '172.29.*.*' (113)
无法连接,可能有几个原因:
1、防火墙,看下iptables ~~~~service iptables status
2、配置文件中绑定了ip,检查bind adderss (my.cnf)
3、配置文件中skip-networking
第二个:ERROR 1130 (HY000): Host '192.168.*.*' is not allowed to connect to this MySQL server
在远程连接时候出现,因为没有权限。
可以使用下面语句给予权限:
[plain] view plain copy
- GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.*.*' IDENTIFIED BY '1234' WITH GRANT OPTION;
其中192.168.*.*是本地ip,root和1234是允许的登录名和密码,这么连接就安全多了。
如果不限制ip,用%表示所有。
第三个:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
是因为忘记密码了。。
最简单方式:/etc/mysql/my.cnf 或/etc/my.cnf
加入skip-grant-tables
重启mysql服务:service mysqld stop/start
可以直接进入:mysql -u root
执行改密码:update user set password = PASSWORD('password') where user = 'root';
把my.cnf中的skip-grant-tables去掉,重启服务
#1.停止mysql数据库
/etc/init.d/mysqld stop
#2.执行如下命令
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
#3.使用root登录mysql数据库
mysql -u root mysql
#4.更新root密码
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
#5.刷新权限
mysql> FLUSH PRIVILEGES;
#6.退出mysql
mysql> quit
#7.重启mysql
/etc/init.d/mysqld restart
#8.使用root用户重新登录mysql
mysql -uroot -p
Enter password: <输入新设的密码newpassword>