mysql执行mysql -h192.168.30.33 -uroot -p报错ERROR 1045 (28000): Access denied for user 'root'@'192.168.30.33' (using password: YES)的解决方法

1、报错详见如下

[root@localhost ~]# mysql -h192.168.30.33 -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'192.168.30.33' (using password: YES)

2、原因分析

  mysql未开启远程访问,因此将不能通过如上的方式连接成功

3、解决措施

  1. 普通方式登入mysql
  2. 若使用root用户登录,则给root授权远程访问(注:用啥账号登录则给啥用户授权即可)
  3. 重启mysql
[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.36-log MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION;   (注:授权的命令)
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

 [root@localhost ~]# cd /usr/local/mysql/support-files/    (注:mysql的安装目录下重启mysql)

 [root@localhost support-files]# ./mysql.server restart
  Shutting down MySQL.... SUCCESS!
  Starting MySQL.. SUCCESS!

再次重新登录即可成功

 

posted @ 2022-08-10 19:58  Syw_文  阅读(77)  评论(0编辑  收藏  举报