搭建blog
安装mysql,设置密码后
退出后无法进入
出现enter password,我直接点击回车,结果出现如果下错误:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)。
提示错误:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)。
解决方案
MySQL安装时默认的用户是root,这里的root是指数据库的用户,root密码一般在初始化MySQL时存放在你的日志文件中,日志文件的存放路径可以通过my.cnf文件进行自定义。
使用如下方法即可解决,本人已验证可行。
1.跳过mysql密码验证
vi /etc/my.cnf
加一行 skip-grant-tables
:wq保存
2.执行如下命令停止mysql数据库
systemctl stop mysql.service
3.使用root登录mysql数据库
mysql -u root mysql
4.更新root密码
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
最新版MySQL请采用如下SQL:
mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
5.刷新权限
mysql> FLUSH PRIVILEGES;
6.退出mysql
mysql> exit
7.注释掉跳过密码验证
vi /etc/my.cnf
#skip-grant-tables
重启 systemctl restart mysql.service
8.使用root用户重新登录mysql
mysql -uroot -p
Enter password: <输入新设的密码newpassword>