1、报错详见如下
[root@localhost ~]# mysql -h192.168.30.33 -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'192.168.30.33'
2、原因分析
mysql未开启远程访问,因此将不能通过如上的方式连接成功
3、解决措施
- 普通方式登入mysql
- 若使用root用户登录,则给root授权远程访问(注:用啥账号登录则给啥用户授权即可)
- 重启mysql
[root@localhost ~]# mysql -uroot -pto 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; (注:授权的命令)0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;0 rows affected (0.01
mysql>exit;
cd /usr/local/mysql/support-files/ (注:mysql的安装目录下重启mysql)
./mysql.server restart
Shutting down MySQL.... SUCCESS!
Starting MySQL.. SUCCESS!
再次重新登录即可成功
1.作者:Syw
2.本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
3.如果文中有什么错误,欢迎指出。以免更多的人被误导。