当出现报错:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
不知道怎么办就可以修改Mysql数据库的密码。
步骤如下:
第一步:登陆服务器管理员权限。
第二步:进入MySQL数据配置文件,最后一行添加:skip-grant-tables
vim /etc/my.cnf
第三步:重启数据库
第四步:此时可以免密登陆了
[root@server1 mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24-log MySQL Community Server (GPL)
第五步骤:修改密码
选择数据库:use mysql;
5.7以上版本运行:update user set password= password("newPassword")where user='root';
5.7以下版本运行:update user set authentication_string= password("newPassword")where user='root';
第六步:退出exit、将第二步文件添加的 skip-grant-tables 取消
第七步:修改完成,重启数据库,此时密码更改成功~~~