MYSQL ROOT 账户 误删除后的恢复办法

首先要保证服务器可以自行远程管理,否则……


1. 修改my.cnf文件中 [mysqld] 区域添加以下一行,临时解除权限限制

skip-grant-tables

2. 重户 Mysql 服务器

service mysqld restart<pre name="code" class="plain">或
/etc/init.d/mysqld restart

 

3. 使用下列命令登陆mysql,无需密码

mysql

4. 登陆后,重新添加root用户

use mysql;
    insert into user set user='root',ssl_cipher='',x509_issuer='',x509_subject='';
    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' where user='root';
然后先退出:

quit;


5. 使用下列命令重新登陆, 设置root的密码

mysql -u root

    update mysql.user set password=password('yourrootpasswd') where user='root';

    update user set host = '%' where user = 'root'; #设置远程机器可访问mysql,如果不需要可不是设置

    flush privileges;

    quit;

6. 修改/etc/my.conf文件,将skip-grant-tables去掉,然后重启mysql
service mysqld restart

或

/etc/init.d/mysqld restart


OK,大功告成!!!


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值