ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
/修改密码后,发现即使使用show databases这样的shell命令也是会出现error:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
真是奇怪了,命名已经密码输入正确了,还要alter user干什么。
根据以上的提示,需要输入一下命令:
mysql> alter user 'root'@'localhost' identified by '*';
Query OK, 0 rows affected (0.01 sec)
mysql> flush priviledges;
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 'priviledges' at line 1
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
下面查看MySQL的Manual文档
mysql> help alter user;
Name: 'ALTER USER'
Description:
Syntax:
ALTER USER syntax for MySQL 5.7.6 and higher:
The ALTER USER statement modifies MySQL accounts. It provides control
over account password expiration. As of MySQL 5.7.6, it also provides
control over authentication, SSL/TLS, and resource-limit properties,
and account locking and unlocking.
To use ALTER USER, you must have the global CREATE USER privilege or
the UPDATE privilege for the mysql database. When the read_only system
variable is enabled, ALTER USER additionally requires the SUPER
privilege.
An error occurs if you try to modify an account that does not exist.
As of MySQL 5.7.8, the IF EXISTS clause can be used, which causes the
statement to produce a warning for each named account that does not
exist, rather than an error.
ALTER USER modifies the mysql.user table row for each affected account
according to the options specified in the statement. Unspecified
properties retain their current values.
Example 1: Change an account's password and expire it. As a result, the
user must connect with the named password and choose a new one at the
next connection:
ALTER USER 'jeffrey'@'localhost'
IDENTIFIED BY 'new_password' PASSWORD EXPIRE;
Example 2: Modify an account to use the sha256_password authentication
plugin and the given password. Require that a new password be chosen
every 180 days:
ALTER USER 'jeffrey'@'localhost'
IDENTIFIED WITH sha256_password BY 'new_password'
PASSWORD EXPIRE INTERVAL 180 DAY;
Example 3: Lock or unlock an account:
ALTER USER 'jeffrey'@'localhost' ACCOUNT LOCK;
ALTER USER 'jeffrey'@'localhost' ACCOUNT UNLOCK;
Example 4: Require an account to connect using SSL and establish a
limit of 20 connections per hour:
ALTER USER 'jeffrey'@'localhost'
REQUIRE SSL WITH MAX_CONNECTIONS_PER_HOUR 20;
URL: http://dev.mysql.com/doc/refman/5.7/en/alter-user.html
例子1中告诉我们,修改了密码之后,在下一次链接,必须用这个命令是上一个密码失效。
ALTER USER 'jeffrey'@'localhost'
IDENTIFIED BY 'new_password' PASSWORD EXPIRE;