系统: CentOS release 6.5 (Final) 内核: 2.6.32-431.el6.x86_64 MySQL版本: 5.5.28-log Source distribution 操作步骤: 1.停止mysql服务 #service mysqld stop 2.以安全模式进入mysql #mysqld_safe --skip-grant-tables & #mysql -u root -p \此时密码为空 3.重建root mysql>USE mysql; mysql>INSERT INTO user(host,user,password) ->VALUES('localhost','root',password('password')); \此处的密码可以后期设置 4.给root用户赋权限 update user set Host='localhost',select_priv='y', insert_priv='y',update_priv='y',Alter_priv='y',delete_priv='y',create_priv='y',drop_priv='y',reload_priv='y',shutdown_priv='y',Process_priv='y',file_priv='y',grant_priv='y',References_priv='y',index_priv='y',create_user_priv='y',show_db_priv='y',super_priv='y',create_tmp_table_priv='y',Lock_tables_priv='y',execute_priv='y',repl_slave_priv='y',repl_client_priv='y',create_view_priv='y',show_view_priv='y',create_routine_priv='y',alter_routine_priv='y',create_user_priv='y',event_priv='y',trigger_priv='y',create_tablespace_priv='y' where user='root'; 5. mysql> FLUSH PRIVILEGES //刷新 6. 退出mysql,重启mysql服务,到此root账户恢复完成 注:给root用户赋权限时,Event_priv、 Trigger_priv、Create_tablespace_priv这三个权限必须添加,否则即使恢复了root用户也不能给其他用户赋予all privileges权限。