误删mysql root密码

数据库 jikk345 439℃ 0评论

 1、停止数据库

停止数据库,并在mysql配置文件my.cnf中添加
skip-grant-tables参数到[mysqld]配置块中
2、启动数据库
免密码登陆到服务器,重建root用户
  1. [root@Qinglin-Student data]# mysql -uroot -p
  2. Enter password:
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 4
  5. Server version: 5.1.73 Source distribution
  6. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql> use mysql;
  12. Database changed
  13. mysql> insert into user set user='root',ssl_cipher=",x509_issuer=",x509_subject="";
  14. mysql> 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';

3、root 重置密码
  1. use mysql
  2. UPDATE user SET Password = password ( '123456' ) WHERE User = 'root' ;
4、注释掉skip-grant-tables,重启服务器

转载请注明:清麟博客 » 误删mysql root密码

喜欢 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址