mysql连接问题

遇到这些问题,网上很多解决方案,一搜就有。在这我简单总结下

第一个: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

  1. 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>

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值