1.編輯MySQL配置文件(忽略授權表) #編輯文件,找到[mysqld],在下面添加一行skip-grant-tables
vi /etc/my.cnf
[mysqld]
skip-grant-tables
:wq! #保存退出
2.重啓服務
#service mysql restart
(-my_print_defaults: [Warning] World-writable config file '/etc/my.cnf' is ignored.
Starting MySQL
-chmod 644 /etc/my.cnf)
3.進入mysql,因爲之前已經跳過輸入密碼登陸,直接回車就可以進入
#mysql -uroot -p
4.修改密碼,這裏跟之前的改密碼的字段不一樣,
>update mysql.user set authentication_string=password(‘newpass‘) where user=‘root‘;
>flush privileges
>quit
5.將/etc/my.cnf文件 skip-grant-tables註釋掉,重啓服務
#service mysql resart
6.使用 mysql -uroot -p 輸入密碼 就可以進了