本文主要是介绍Ubuntu/Debian(Raspbian)进入MySQL报错:ERROR 1698 (28000): Access denied for user 'root'@'localhost'的解决方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
树莓派安装MySQL未提示设置密码,之后在sudo下无需密码即可连接,其它输入报错ERROR 1698 (28000)
附:远程连接MySQL出现1130错误解决方法
# 问题场景:
在树莓派3B+,系统Raspbian(Debian9.4),安装MySQL:
sudo apt-get install mysql-serversudo apt-get install mysql-client
安装过程中未提示设置密码。
检查进程:
sudo netstat -tap | grep mysql
显示:
tcp 0 0 localhost:mysql 0.0.0.0:* LISTEN 1369/mysqld
说明数据库服务成功启动。
尝试登录mysql:
mysql -u root -p
报错:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
重启服务:
sudo service mysql restart
还是报错:ERROR 1698 (28000)!!!
是不是很气?
打开配置文件:
sudo vim /etc/mysql/debian.cnf
两个root账号密码竟然为空,也没有用随机值填充。
# 目前遇到的问题:
安装mysql-server的过程没有提示输入root的password
安装成功后,输入指令mysql -uroot,提示Access denied for user ‘root’@’localhost’
输入sudo mysql -uroot可以直接连接成功
输入sudo mysql -uroot -p后回车输入任意password也可以直接连接成功
输入mysql -h 127.0.0.1 -P 3306 -uroot -p提示Access denied for user ‘root’@’localhost’
# 解决方法:
sudo mysql -u root
成功登录!
但问题彻底解决了吗?……还没有!
- 需要给root设置password
- 需要将用户表中plugin字段由auth_plugin设置成mysql_native_password
修改密码:
noneDataBase> use mysql;
mysql> UPDATE user SET password=PASSWORD('123456') WHERE user='root';
mysql> UPDATE user SET plugin='mysql_native_password' WHERE user='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;
重启服务:
sudo systemctl restart mysqlsudo systemctl status mysql
问题已经解决(无论是否加sudo,都必须使用正确的密码,才能连接数据库)
# 如需远程连接MySQL:
sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf将bind-address=127.0.0.1改成bind-address=0.0.0.0
然后:
sudo rebootvia……
对了,如果你需要完整卸载MySQL:
sudo apt-ge autoremove --purge mysql-server
sudo apt-get remove mysqyl-server
sudo apt-get remove mysql-common #重要
sudo apt-get autoremove mysql-server
Thanks Kevin_miu
# 远程连接MySQL出现1130错误解决方法:
mysql -u root -pnoneDataBase>use mysql;mysql>select 'host' from user where user='root';mysql>update user set host = '%' where user ='root';mysql>flush privileges;mysql>select 'host' from user where user='root';
修改后即可尝试远程连接,如果不行建议:sudo systemctl restart mysql或者reboot。
这篇关于Ubuntu/Debian(Raspbian)进入MySQL报错:ERROR 1698 (28000): Access denied for user 'root'@'localhost'的解决方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!