最初mysql -u root
运行良好。
然后我尝试使用以下命令重置root
用户密码
UPDATE set authentication_string=PASSWORD("password") where User='root';
但当我尝试mysql -u root -ppassword
时,它正在抛出
access denied for user 'root'@'localhost' (using password: NO)
因此,要修复上述解决方案,请执行以下步骤:
- 首先使用
which mysql
搜索系统中mysql脚本的位置
/usr/local/bin/mysql
- 运行
cd /usr/local/bin
- 然后查找
mysql.server
文件并执行mysql.server stop
输出为:
关闭MySQL
。成功!
- 运行
killall mysqld mysqld_safe
- 运行
mysqld_safe --skip-grant-tables &
- 然后尝试
mysql -u root
,它会起作用
所以下一步是将根密码更新回<no-password>
- 运行
use mysql;
- 运行
Update user set authentication_string='' where User='root';
注意:要更新mysql8.0+密码,请始终使用
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';