剛剛安裝完mysql就提示密碼過期!

mysql 5.7.14安裝完後登陸報錯,意思是密碼過期

[root@mysql]# mysql -u root -p

Enter password:

ERROR 1862 (HY000): Your password has expired. 

To log in you must change it using a client that supports expired passwords.


解決辦法:

1.在my.cnf  mysqld 部分加入 skip-grant-tables 參數。

[mysqld]
skip-grant-tables

2.重啓mysql數據庫,然後登陸

[root@llmj-mysql-40-115 tools]# mysql -u root -p
Enter password:   #這裏直接回車,不需要密碼即可登陸
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.14-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, 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.

3.查看mysql的用戶狀態password_expired :

>select host,user,password_expired,account_locked from mysql.user;
+-----------+-----------+------------------+----------------+
| host      | user      | password_expired | account_locked |
+-----------+-----------+------------------+----------------+
| localhost | root      | Y                | N              |
| localhost | mysql.sys | N                | Y              |
+-----------+-----------+------------------+----------------+
3 rows in set (0.00 sec)

y說明密碼已經過期,可以改成N,就是未過期

>update mysql.user set password_expired='N';
Query OK, 1 row affected (0.03 sec)
Rows matched: 2  Changed: 1  Warnings: 0

4.然後註釋掉skip-grant-tables參數重啓mysql,用過期的密碼就可以登陸了,登陸之後可以用下面的命令修改密碼

>alter user user() identified by '123456';
Query OK, 0 rows affected (0.03 sec)

>flush privileges;
Query OK, 0 rows affected (0.03 sec)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章