欢迎光临
我们一直在努力

mysql误删了root账户怎么办?

今天手贱,不小心通过phpmyadmin把mysql仅有的root账户删了,删了,了。。。。瞬间服务器的几个网站都无法正常连接数据库,phpmyadmin直接退出无法登陆。

肿么办?

通过检索百度的各种经验无法正常恢复root账户,不过通过一个上午的摸索,终于搞定,简要步骤如下:

1、在系统服务中停止mysql服务;

2、在mysql安装目录下找到my.ini,然后在my.ini中找到以下片段[mysqld];另起一行加入代码:“skip-grant-tables”(不带引号) 并保存;

3、启动mysql服务,打开CMD窗口,将命令切换至mysql的bin目录下,输入mysql命令,显示如下窗口:

CMD command

4、输入以下命令,添加root用户和密码(用户名root,密码123456):

INSERT INTO mysql.user (Host,User,Password) VALUES( ‘localhost’, ‘root’,password( ‘123456’));

5、root用户设置权限:

update mysql.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’ where user=’root’;commit;

6、把my.ini刚才加入的那行删除并重启服务

7、用root用户登录,OK!

以上操作结束后使用phpmyadmin登入mysql,检查root权限,如果有缺失的root权限可以通过以下命令逐项添加:

456 789

附:添加权限命令:

                    update mysql.user set Select_priv =’Y’ where user = ‘root’;
 
                    update mysql.user set Insert_priv =’Y’ where user = ‘root’;
                    update mysql.user set Update_priv =’Y’ where user = ‘root’;
                    update mysql.user set Delete_priv =’Y’ where user = ‘root’;
                    update mysql.user set Create_priv =’Y’ where user = ‘root’;
                    update mysql.user set Drop_priv =’Y’ where user = ‘root’;
                    update mysql.user set Reload_priv =’Y’ where user = ‘root’;
                    update mysql.user set Shutdown_priv =’Y’ where user = ‘root’;
                    update mysql.user set Process_priv =’Y’ where user = ‘root’;
                    update mysql.user set File_priv =’Y’ where user = ‘root’;
                    update mysql.user set Grant_priv =’Y’ where user = ‘root’;
                    update mysql.user set References_priv =’Y’ where user = ‘root’;
                    update mysql.user set Index_priv =’Y’ where user = ‘root’;
                    update mysql.user set Alter_priv =’Y’ where user = ‘root’;
                    update mysql.user set Show_db_priv =’Y’ where user = ‘root’;
                    update mysql.user set Super_priv =’Y’ where user = ‘root’;
                    update mysql.user set Create_tmp_table_priv =’Y’ where user = ‘root’;
                    update mysql.user set Lock_tables_priv =’Y’ where user = ‘root’;
                    update mysql.user set Execute_priv =’Y’ where user = ‘root’;
                    update mysql.user set Repl_slave_priv =’Y’ where user = ‘root’;
                    update mysql.user set Repl_client_priv =’Y’ where user = ‘root’;
                    update mysql.user set Create_view_priv =’Y’ where user = ‘root’;
                    update mysql.user set Show_view_priv =’Y’ where user = ‘root’;
                    update mysql.user set Create_routine_priv =’Y’ where user = ‘root’;
                    update mysql.user set Alter_routine_priv =’Y’ where user = ‘root’;
                    update mysql.user set Create_user_priv =’Y’ where user = ‘root’;
                    update mysql.user set Event_priv =’Y’ where user = ‘root’;
                    update mysql.user set Trigger_priv =’Y’ where user = ‘root’;

 

未经允许不得转载:黄公子驿站 » mysql误删了root账户怎么办?