修改本地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