1. 程式人生 > >解決忘記mysql密碼的問題(linux)

解決忘記mysql密碼的問題(linux)

1:開啟/etc/my.cnf
2:找到mysqld
3:新增skip_grant_tables在mysqld下面,然後退出儲存wq
4:重啟service mysql restart
5:mysql -u user -p 回車 直接進去
6:然後執行命令 update mysql.user set password=password(‘root’) where user=‘root’;如果提示ERROR 1054 (42S22): Unknown column ‘password’ in 'field list’的錯誤,是因為MYSQL版本過高,然後執行update mysql.user set authentication_string=password(‘root’) where user=‘root’
7:flush privileges;
8:exit;
9:去掉my.cnf的skip_grant_tables
10:重啟service mysql restart
11:完事

名詞解釋
skip_grant_tables:不啟動grant-tables授權表
flush privileges:新設定使用者或更改密碼後需用flush privileges重新整理MySQL的系統許可權相關表,否則會出現拒絕訪問)

本文參考:http://blog.sina.com.cn/s/blog_cca6ddf80102w61m.html