龙空技术网

5.linux系统中 mysql -u root -p 并且录入密码报错

一起去成长 46

前言:

如今大家对“mysql设置密码报错”大致比较关注,看官们都需要剖析一些“mysql设置密码报错”的相关文章。那么小编也在网摘上收集了一些对于“mysql设置密码报错””的相关文章,希望姐妹们能喜欢,大家快快来学习一下吧!

MySQL登录报错 ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

一.问题:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
二、原因:
错误 1045 (28000):用户“root”@“本地主机”的访问被拒绝(使用密码:是)简单的说,就是用户root没有使用权限。
三、解决方法:(1)若MySQL已经没有启动,重启MySQL服务器
systemctl restart mysqld  或者  systemctl restart mariadb
(2)修改密码

1.修改/etc/my.cnf文件,在[mysqld]中添加skip-grant-tables(登录时跳过权限检查)

vi /etc/my.cnf

添加超级权限,目的mysql免密登录,注意要放在上面【mysql】的下面,如果放到最下面没有效果。

skip-grant-tables

2. 重启数据库

systemctl restart mysqld

3.修改密码

3.1先登录mysql

mysql -uroot -p

会让你输入密码,直接点击回车即可。

3.2输入use mysql

use mysql

3.3设置密码 Abcdefg@123】设置自己的密码

set password for `root`@`localhost`=password('Abcdefg@123');

如果遇到

ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement 

3.4.输入flush privileges;

flush privileges;

3.5接下来再次输入set password for `root`@`localhost`=password('Abcdefg@123');即可

set password for `root`@`localhost`=password('Abcdefg@123');

或者执行

update mysql.user set authentication_string ='Abcdefg@123' where user="root";

4.退出

exit

5.将my.cnf中的skip-grant-tables去除

vi /etc/my.cnf

6.重启服务

systemctl restart mysqld

标签: #mysql设置密码报错