如何重置mysql的密码

本文介绍了两种重置MySQL密码的方法:一种是在已知旧密码的情况下直接更新密码;另一种是在忘记密码的情况下,通过临时禁用权限表来重置密码。文章详细展示了每一步的操作命令。
  1. 如何重置mysql的密码  
  2.   
  3. 如果知道密码,则通过以下方式修改;  
  4.   
  5.     gaurav@gaurav:~$ mysql --user=root --pass mysql  
  6.     Enter password:  
  7.        
  8.     mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root';  
  9.     Query OK, 2 rows affected (0.04 sec)  
  10.     Rows matched: 2  Changed: 2  Warnings: 0  
  11.        
  12.     mysql> flush privileges;  
  13.     Query OK, 0 rows affected (0.02 sec)  
  14.        
  15.     mysql> exit  
  16.     Bye  
  17.       
  18. 如果忘记密码,则先停止mysql,然后加上参数skip-grant-tables重新启动mysql server  
  19.   
  20.     root@gaurav:~# /etc/init.d/mysql stop  
  21.        
  22.     Now you should start up the database in the background, via the mysqld_safe command:  
  23.        
  24.     root@gaurav:~# /usr/bin/mysqld_safe --skip-grant-tables &  
  25.     [1] 4271  
  26.     Starting mysqld daemon with databases from /var/lib/mysql  
  27.     mysqld_safe[6763]: started  
  28.       
  29. 然后登陆mysql,修改密码  
  30.   
  31.     root@gaurav:~$ mysql --user=root mysql  
  32.     Enter password:  
  33.        
  34.     mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root';  
  35.     Query OK, 2 rows affected (0.04 sec)  
  36.     Rows matched: 2  Changed: 2  Warnings: 0  
  37.        
  38.     mysql> flush privileges;  
  39.     Query OK, 0 rows affected (0.02 sec)  
  40.        
  41.     mysql> exit  
  42.     Bye  
  43.   
  44. 最后重启mysql server就可以了。  
  45.   
  46.     root@gaurav:~# /etc/init.d/mysql start  
  47.     Starting MySQL database server: mysqld.  
  48.     Checking for corrupt, not cleanly closed and upgrade needing tables..  
  49.       
  50. 用新密码登陆验证下  
  51.   
  52.     root@gaurav:~# mysql --user=root --pass=new-password-here  
  53.     Welcome to the MySQL monitor.  Commands end with ; or \g.  
  54.     Your MySQL connection id is 5 to server version: 5.0.24a-Debian_4-log  
  55.        
  56.     Type 'help;' or '\h' for help. Type '\c' to clear the buffer.  
  57.        
  58.     mysql> exit  
  59.     Bye  

转载于:https://www.cnblogs.com/focai/p/4489796.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值