MYSQL5.7 忘記ROOT密碼/初始化ROOT密碼


編輯my.cnf允許空密碼登錄

1 [root@7Core ~]# vi /etc/my.cnf
2 #在[mysqld]下加入一行
3 skip-grant-tables=1

重新啟動Mysql服務

1 [root@7Core ~]# systemctl restart mysqld.service

使用Root登錄數據庫、使用mysql數據庫、修改root密碼、退出數據庫

1 [root@7Core ~]# mysql -u root
2 mysql> use mysql;
3 mysql> update user set authentication_string = password('新密碼'),password_last_changed=now() where user='root';
4 mysql> exit;

再次打開my.cnf,將skip-grant-tables=1刪掉,保存退出

1 [root@7Core ~]# vi /etc/my.cnf
2 #刪除skip-grant-tables=1

重啟Mysql服務

1 [root@7Core ~]# systemctl restart mysqld.service


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM