Linux中MYSQL5.7出现ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

编程入门 行业动态 更新时间:2024-10-09 08:25:39

Linux中MYSQL5.7出现<a href=https://www.elefans.com/category/jswz/34/1771302.html style=ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)"/>

Linux中MYSQL5.7出现ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

一 关于出现”ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)“错误的解决:

1 查看版本和修改配置

mysql -V								//查看对应的版本号,一般我们的服务器版本为mysql5.7.30
whereis myf							//查找mysql对应的配置文件,路径一般为/etc/myf,mysql8.0以上在/etc/mysql/conf.d/mysqlf
vim /etc/myf在[mysqld]中添加以下内容:
skip-grant-tables

2 重启服务

service mysqld restart	

3 修改密码

mysql -uroot -p								//输入后直接按enter即可,无需输入密码
use mysql
select * from user;							//查看是否有authentication_string字段
update user set authentication_string=password("你的新密码") where user='root';	//若数据库是5.7及以上的用该命令.因为5.7之前没有authentication_string字段,5.7之前的字段叫password
//update user set password=password("你的新密码") where user="root";		//5.7之前的版本用这个命令
flush privileges;	

4 修改登录主机

//update user set host = '%' where user = 'root';				//修改mysql只能在本地登录而无法远程登录(建议用下面的)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你刚刚改的密码';		//这里面*.*代表是所有库.所有表, root是用户名, %代表所有ip都可访问,也可指定ip访问,例如'root'@'172.17.5.90',123456代表root用户的密码;
flush privileges;
select host,user from user;										//查看host可以看到localhsot已经变成%。
quit;

5 修改回配置

vim /etc/myf
然后去掉刚刚添加的skip-grant-tables。

6 重启服务

service mysqld restart
再次登录即可成功

更多推荐

Linux中MYSQL5.7出现ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (u

本文发布于:2024-02-06 04:17:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1746178.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ERROR   Linux   Access   localhost   password

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!