1.修改文件目錄為/etc/my.cnf的文件;
在[mysqld]的段中加上一句:skip-grant-tables,保存文件重啟數據庫;
例如:
[mysqld]
skip-grant-tables
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=
2。修改密碼:
3,把/etc/my.cnf文件內容修改回來,重啟數據庫
注意:步驟三的時候:使用:update mysql.user set authentication_string=password("你的密碼大寫字母和數字盡量多而復雜") where user="root";(不要去掉;)