在 MySql 5.7.17 下,上述指令不起作用,并且我始终没有收到任何反馈或以下错误消息:
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 'UPDATE mysql.user SET password=password("elephant7") where user="root"' at line ...
我在命令行上尝试了以下UPDATE
:
UPDATE mysql.user SET Password = PASSWORD('elephant7') WHERE User='root';
我真的看不出我的错误了。我也尝试过不使用 ;
。
最佳答案
不建议直接在 mysql.user
表上使用 UPDATE
来更改密码。你应该使用 SET PASSWORD
相反:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('elephant7');
More information on MySQL: Assigning Account Passwords
您的UPDATE
命令可能不起作用,因为password
列被authentication_string
替换on MySQL 5.7.6 .
The
authentication_string
column in themysql.user
table now stores credential information for all accounts. Thepassword
column, previously used to store password hash values for accounts authenticated with themysql_native_password
andmysql_old_password
plugins, is removed.
如果您直接更改授权表,您还必须使用FLUSH PRIVILEGES
语句重新加载表:
If you modify the grant tables directly using statements such as
INSERT
,UPDATE
, orDELETE
(which is not recommended), the changes have no effect on privilege checking until you either tell the server to reload the tables or restart it. Thus, if you change the grant tables directly but forget to reload them, the changes have no effect until you restart the server. This may leave you wondering why your changes seem to make no difference!To tell the server to reload the grant tables, perform a flush-privileges operation. This can be done by issuing a
FLUSH PRIVILEGES
statement.
因此,直接更改授权表上的密码的 UPDATE
命令必须如下所示,使用正确的列和 FLUSH PRIVILEGES
声明:
UPDATE mysql.user SET authentication_string = PASSWORD('elephant7') WHERE User = 'root';
FLUSH PRIVILEGES;
关于mysql - 无法使用 UPDATE 更改 MySQL 上的用户密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41218479/