標籤:alter 使用者 new HERE 設定 oba 設定檔 The 配置
1、修改登入設定
vim /etc/my.cnf #或/etc/mysql/my.cnf [mysqld] skip-grant-tables #新加
2、重啟mysql服務
3、直接mysql登入,並修改密碼
update mysql.user set authentication_string=password('新密碼') where User='root'; #5.7中儲存密碼欄位是這個,desc先看下儲存密碼欄位。其他版本一般如下修改#mysql> UPDATE mysql.user SET Password = password ('new-password') WHERE User = 'root' ; #如遇到報錯 You must reset your password using ALTER USER statement before executing this statement. 原因是密碼有效期間已到,需要執行 1. ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; #設定密碼永不到期,改回預設方法 alter user 'root'@'localhost' password expire default 2. 或者 set global default_password_lifetime=0 或直接寫在設定檔裡面,到期時間為0表示永不到期,全域生效。推薦上中方法僅特定使用者密碼不到期flush privileges; #使用update修改密碼必須要執行此步或者set password=passwprd('新密碼');#不須重新整理授權表,完整格式 SET PASSWORD FOR 'root'@'localhost'=PASSWORD('newpassword');
4、修改設定檔
刪除
skip-grant-tables
重啟服務
MySQL 5.7 忘記密碼後修改密碼