Mysql 5.7數據庫原來一直都能正常訪問,突然訪問不了,查看日誌提示數據庫需要修改密碼,
具體解決辦法如下操作:
Windows 下:
mysql的bin目錄下,
mysql> use mysql;
判斷“password_expired”是否爲Y
mysql> select authentication_string,password_expired from user where user='root';
判斷“default_password_lifetime”是否爲0
mysql> show VARIABLES like "%password%";
“password_expired”爲Y的解決方法
修改“password_expired”的值:
update user set authenticatio_string=password('123456'),password_expired='N' where user='root';
“default_password_lifetime”爲0解決方法
修改“default_password_lifetime”的值:
mysql> set GLOBAL default_password_lifetime=0;
重啓mysql:
net restart mysqld
Linux下:
1、查找問題
1.1、跳過數據庫權限驗證:
vim /etc/my.cnf
在my.cnf文件最後添加skip-grant-tables並保存
1.2、重啓mysql:
sudo systemctl restart mysqld
mysql> use mysql;
1.3、判斷“password_expired”是否爲Y
mysql> select authentication_string,password_expired from user where user='root';
1.4、判斷“default_password_lifetime”是否爲0
mysql> show VARIABLES like "%password%";
2、“password_expired”爲Y的解決方法
2.1、修改“password_expired”的值:
update user set authenticatio_string=password('123456'),password_expired='N' where user='root';
2.2、恢復數據庫權限驗證:
vim /etc/my.cnf
在my.cnf文件最後去掉skip-grant-tables並保存
2.3、重啓mysql:
sudo systemctl restart mysqld
3、“default_password_lifetime”爲0解決方法
3.1、修改“default_password_lifetime”的值:
mysql> set GLOBAL default_password_lifetime=0;
3.2、恢復數據庫權限驗證:
vim /etc/my.cnf
在my.cnf文件最後去掉skip-grant-tables並保存
3.3、重啓mysql:
sudo systemctl restart mysqld
原文鏈接:https://blog.csdn.net/shirenkan/article/details/105321160