Mysql5 7找回root密碼

2021-09-06 22:49:45 字數 1612 閱讀 6780

1.修改my.cnf

在[mysqld]段新增配置skip-grant-tables

2.重啟mysql

# /etc/init.d/mysqld restart

stopping mysqld: [ ok ]

starting mysqld: [ ok ]

3.登入mysql
# mysql

welcome to the mysql monitor. commands end with ; or \g.

your mysql connection id is 8

server version: 8.0.13 mysql community server - gpl

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>

4.修改密碼

注意mysql5.7使用下面的語句修改密碼

mysql> alter user 'root'@'localhost' identified by '123456';

error 1290 (hy000): the mysql server is running with the --skip-grant-tables option so it cannot execute this statement

此報錯通過度娘查詢,需要執行下列語句後再修改密碼

mysql> flush privileges;

query ok, 0 rows affected (0.00 sec)

此報錯說明密碼不符合安全策略,預設的密碼強度至少滿足:大/小寫字母+阿拉伯數字+特殊字元,長度不小於8位

mysql> alter user 'root'@'localhost' identified by '123456';

error 1819 (hy000): your password does not satisfy the current policy requirements

5.再次修改密碼生效
mysql> alter user 'root'@'localhost' identified by '[email protected]';

query ok, 0 rows affected (0.08 sec)

mysql> flush privileges;

query ok, 0 rows affected (0.00 sec)

6.修改my.cnf去掉skip-grant-tables配置,重啟mysql使用新密碼登入即可

mysql5 7 修改root 密碼

假如忘記mysql的root 密碼是什麼之後如何修改密碼 我的mysql是自己原始碼安裝的,mysql.server存放在 usr local mysql support files檔案當中 1 先關閉mysql usr local mysql support files mysql.server ...

MySql 5 7 修改root密碼

1.找到配置檔案my default.ini 然後將其開啟,可以選擇用記事本開啟 2.開啟後,搜尋mysqld關鍵字 找到後,在mysqld下面新增skip grant tables,儲存退出。ps 若提示不讓儲存時,可以將該檔案剪下到桌面,更改儲存後再複製到mysql目錄下 3.儲存後重啟mysq...

MySQL5 7修改root密碼

mysql 版本檢視 mysql version 版本在5.7以上 編輯檔案 vim etc my.cnf mysqld 下新增儲存 skip grant tables 重啟mysql服務 service mysqld restart 輸入mysql命令進入mysql命令列 修改root使用者密碼 ...