MYSQL不能从远程连接的解决方法

为了在其它电脑上能用root用户登录,需进行以下动作:

首先在mysql服务器端打开mysql

1、 mark>mysql -u root -p

//输入密码,进入MySQL服务器

2、mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password'; (注意要带单引号)

//赋予任何主机访问数据的权限

3、mysql>FLUSH PRIVILEGES

//修改生效

4、mysql>EXIT

//退出MySQL服务器

这样就可以在其它任何的主机上以root身份登录啦!

客户端(windows)

c:program filesmysqlmysql server 5.1in>mysql -h 192.168.0.249 -uroot -p

enter password:

远程报错:

ERROR 2003(HY000):Can't connect to MySQL server on '192.168.0.249' (10065)

把linux服务器的防火墙添加端口tcp: 3306后就OK了。

c:program filesmysqlmysql server 5.1in>mysql -h 192.168.0.249 -uroot -p

enter password:

Welcome to the MySQL monitor. Commands end with ; or g.

Your MySQL connection id is 13

Server version:4.1.22-standard-log

Type 'help' or 'h' for help. Type 'c' to clear the buffer.

mysql>

如果出现: 1045 Access denied for user 'root'@'192.168.1.3' (using password:YES) 错误的话。

是因为上述第二步密码为'%' 所以不用加密码即可。

原文地址:https://www.cnblogs.com/angryprogrammer/p/3658163.html