mysql登录报错“Access denied for user 'root'@'localhost' (using password: YES”)的处理方法

环境

CentosOS 6.5 ,已安装mysql

情景

root密码忘记,使用普通用户无法登录

解决

问题一 无法使用mysql命令

参考文章:https://www.cnblogs.com/comeping/p/8576694.html

加入环境变量PATH

# PATH=$PATH:/usr/local/mysql/bin
# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
# source /etc/profile

问题二 Access denied for user

登录时出现如下

# mysql -u root -p 
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

我不知道root密码,也不知道输的对不对,我就按忘记密码处理了

参考文章:https://blog.csdn.net/qq_35389417/article/details/78910974

在Linux下忘记MySQL密码后我们可以通过一个mysql的参数–skip-grant-tables &轻松解决这个问题
亲测在CentOS有效
其中 --skip-grant-tables 的意思是跳过授权表,通过此参数来跳过输入密码,后面跟得 & 符号是表示设置此进程为后台进程

具体操作过程如下:
1.首先关闭掉MySQL系统服务: service mysqld stop

2.使用命令跳过输入密码过程:mysqld_safe --skip-grant-tables &

然后再输入mysql,进入mysql

3.进入 mysql数据库,然后通过语句修改密码:

use mysql
update user set password=password("root1234") where user='root'; //修改用户:root的密码成为:root1234
flush privileges//刷新MySQL的系统权限相关表,否则会出现拒绝访问 忘记输入的话重启mysql服务也可以

重启mysql系统服务后就可以用新密码进入MySQL了: service mysqld restart

猜你喜欢

转载自www.cnblogs.com/xcsn/p/10424677.html