1. 程式人生 > >linux mysql忘記root密碼

linux mysql忘記root密碼

修改本地mysql目錄中的my.ini檔案

vim /etc/my.cnf

在[mysqld]下新增如下配置

skip-grant-tables

重啟mysql服務

service mysqld restart

進入MySQL

mysql -uroot
> use mysql;

修改密碼


update user set authentication_string = password("123456") where user = "root";

注意,不同MySQL版本的密碼欄位名不一樣,我裝的版本命名是authentication_string,其他版本可能命名是"password"

**刪除之前 /etc/my.cnf skip-grant-tables **

一定要記住還原之前的修改,否則有安全隱患

再次重啟mysql服務

service mysqld restart

完成!!!