我忘记了 mysql 的密码,所以我尝试使用以下步骤更改它 -
1)停止Mysql服务器
2)使用以下命令以安全模式启动服务器sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
3)使用打开mysql命令行sudo /usr/local/mysql/bin/mysql -u root
4)使用更新密码UPDATE mysql.user SET authentication_string=PASSWORD('NewPassword') WHERE User='root';
但在这一步我收到以下错误消息 -
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('NewPassword') WHERE User='root'' at line 1
Run Code Online (Sandbox Code Playgroud)
有人可以告诉如何解决这个错误吗?
在 8.0.15(可能早于该版本)上,PASSWORD() 函数不起作用,如下面的评论中所述。你必须使用:
UPDATE mysql.user SET authentication_string='password' WHERE User='root';
Run Code Online (Sandbox Code Playgroud)