尝试在mysql中更改密码时出错

Posted

技术标签:

【中文标题】尝试在mysql中更改密码时出错【英文标题】:Error on trying to change password in mysql 【发布时间】:2018-12-26 01:50:11 【问题描述】:

我忘记了mysql的密码,所以我尝试使用以下步骤更改它-

1) 停止Mysql服务器

2)使用sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables以安全模式启动服务器

3) 使用sudo /usr/local/mysql/bin/mysql -u root打开mysql命令行

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

谁能告诉我如何解决这个错误?

【问题讨论】:

你用的是哪个版本的mysql? 【参考方案1】:

问题清楚地表明,它的语法不正确。 您应该使用官方 MYSQL 程序来重置密码,其中包括 create text file with command 然后 restarting the mysqld with text file input with mysqld --init-file=/home/me/mysql-init &' 命令。

请参阅 unix [此处][1] 的官方 root 密码重置选项。

[1]https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html

【讨论】:

【参考方案2】:

在 8.0.15(可能早于该版本)上,PASSWORD() 函数不起作用,如下面的 cmets 所述。你必须使用:

UPDATE mysql.user SET authentication_string='password' WHERE User='root';

Original answer here

【讨论】:

以上是关于尝试在mysql中更改密码时出错的主要内容,如果未能解决你的问题,请参考以下文章

在 root 中更改密码并在访问 localhost/phpmyadmin 时出错

建立数据库连接时出错 - WP 主机更改了密码

phpmyadmin 密码更改 - 在 wordpress 上创建数据库连接时出错

如何在 CentOS7 上更改 MySQL root 帐户密码?

如何在 CentOS7 上更改 MySQL root 帐户密码?

mysql不会更改我的root密码,