1.场景:在linux CentOS7安装mysql时出现错误:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
2.解决方式:
(1)停止mysql数据库:
systemctl stop mysqld
(2)执行下面的命令:
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
(3)使用root登录mysql
mysql -u root mysql
(4)更新root密码:
UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
(5)刷新权限:
FLUSH PRIVILEGES;
(6)重新登陆