我一直收到此错误。我一直在查看一些 QA 站点,尝试重置我的本地 mysql 密码。我已添加以下内容skip grant tables
,[mysqld]
现在我正在安全模式下运行。我已遵循以下步骤
mysqld_safe --skip-grant-tables &
use mysql;
update user set password=PASSWORD(”my_password”) 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 '("my_password") where user="root"' at line 1
我也试过
UPDATE mysql.user SET
authentication_string=PASSWORD(''),
plugin='mysql_native_password'
WHERE User='root' AND Host='localhost';
和这个
ALTER USER 'root'@'localhost IDENTIFIED WITH mysql_native_password BY '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 'Ihost IDENTIFIED WITH mysql_native_password BY 'root'' at line 1
目前不确定如何重置密码。
答案1
我每次都会更新适合我的内容,请按照以下步骤操作
以 root 用户身份登录
sudo mysql -u root
选择 mysql 数据库
use mysql;
检查所需用户使用的插件,如果是 auth_login?使用此查询将其更改为 mysql_native_password
UPDATE user SET plugin='mysql_native_password' WHERE User='root';
现在使用此查询来更新 root 或任何其他用户的密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newpassword';
使用以下命令重启 mysql 服务
sudo systemctl restart mysql