密码丢失修改密码
mysql> use mysql ERROR 1820 (HY000): You must SET PASSWORD before executing this statement mysql> exit Bye [root@localhost ~]# /etc/init.d/mysql stop ERROR! MySQL server process #17602 is not running! [root@localhost ~]# ps -ef|grep mysql root 18980 15786 0 21:11 pts/3 00:00:00 grep mysql
[root@localhost ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & [1] 19128 [root@localhost ~]# 150610 21:11:39 mysqld_safe Logging to '/var/lib/mysql/localhost.localdomain.err'. 150610 21:11:39 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql mysql -u root mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.24 MySQL Community Server (GPL) Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> UPDATE user SET Password=PASSWORD('broadtech') where USER='root'; Query OK, 0 rows affected (0.00 sec) Rows matched: 4 Changed: 0 Warnings: 0 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> quit Bye [root@localhost ~]# /etc/init.d/mysql restart Shutting down MySQL..150610 21:12:36 mysqld_safe mysqld from pid file /var/lib/mysql/localhost.localdomain.pid ended SUCCESS! Starting MySQL. SUCCESS! [1]+ Done mysqld_safe --user=mysql --skip-grant-tables --skip-networking [root@localhost ~]# You have new mail in /var/spool/mail/root [root@localhost ~]# [root@localhost ~]# ps -ef |grep mysql root 19496 1 0 21:12 pts/3 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/localhost.localdomain.pid mysql 19597 19496 2 21:12 pts/3 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/localhost.localdomain.err --pid-file=/var/lib/mysql/localhost.localdomain.pid root 19627 15786 0 21:12 pts/3 00:00:00 grep mysql
最后修改完成
[root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.24 Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
但是登陆后,执行还是会报错
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement,必须重新设置一次密码:
[root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 35 Server version: 5.6.24 Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use mysql ERROR 1820 (HY000): You must SET PASSWORD before executing this statement mysql> SET PASSWORD = PASSWORD('broadtech'); Query OK, 0 rows affected (0.00 sec) mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql>
在你用客户端登陆时,会报密码过期, 所以需要再改一次密码
官网说:
It is possible to “reset” a password by setting it to its current value. As a matter of good policy, it is preferable to choose a different password.
所以改为123456
mysql> SET PASSWORD = PASSWORD('123456'); Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) mysql> mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)