1.停止mysql服務器
sudo service mysql stop
2.啟動mysql服務
sudo mysqld_safe --skip-grant-tables
3.登陸 mysql
mysql
4.重新載入權限
flush privileges;
5.進入數據庫
use mysql
6.查詢user用戶
select user,host,password from user
7.向root用戶授予權限
GRANT USAGE ON *.* TO 'root'@'localhost' IDENTIFIED BY 'Password' WITH GRANT OPTION;
grant all on *.* to 'root'@'localhost' identified by 'password';
8.刷新,退出
flush privileges;
exit;
此時便可以訪問數據庫了!!!