1045: Access denied for user 'root'@'localhost' (using password: YES)

1045: Access denied for user ‘root’@‘localhost’ (using password: YES)

  用户在linux装了mysql之后,可以使用远程ssh进入linux之后可以使用mysql,但是使用远程连接时出了问题
  Error 1045:Access denied for user 'root'@'localhost' (using password: YES)
  由提示可知,密码是正确的,但是却拒绝连接。是因为您的mysql并没有向公网开放连接,也就是说没有授权外网连接。

解决方案:
 1. 使用ssh方式连接linux;
 2. 执行如下代码,进入你的mysql数据库(这里使用的时root用户)

# mysql -u root -p
Enter password: (这里输入mysql登陆密码,输入时没有任何反应,输入完回车即可)

 3. 执行下面语句

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xxxx' WITH GRANT OPTION; 
Query OK, 0 rows affected (0.00 sec)

mysql>  flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

service mysqld restart

 第一个语句中的xxxx是您mysql的登陆密码。其他的直接执行就行。

 此时外网链接基本没问题了

发布了39 篇原创文章 · 获赞 19 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_35394434/article/details/102727897