java.sql.SQLException: Access denied for user 'root'

时间:2021-09-30 19:21:44

程序在连接远程 mysql服务器时出错 java.sql.SQLException: Access denied for user 'root'@'192.168.27.129' (using password: YES)

本机IP为'192.168.27.129'

进入mysql命令行:

MySQL>use mysql;

MySQL>select host,user from user;

查看得信息如下,也没有限制不让本机连接mysql呢。

+-----------------------+------+
| host                  | user |
+-----------------------+------+
| %                     | root |
| 127.0.0.1             | root |
| ::1                   | root |
| localhost             | root |
| localhost.localdomain | root |
+-----------------------+------+

难道是默认不让root远程登陆??

MySQL>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xuxu' WITH GRANT OPTION

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

3、MySQL>FLUSH PRIVILEGES

程序再用root和密码 ,登录,结果成功!