如何重置mysql的密码

原文链接:http://www.javaarch.net/jiagoushi/702.htm

如何重置mysql的密码

如果知道密码,则通过以下方式修改;

	gaurav@gaurav:~$ mysql --user=root --pass mysql
	Enter password:
	 
	mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root';
	Query OK, 2 rows affected (0.04 sec)
	Rows matched: 2  Changed: 2  Warnings: 0
	 
	mysql> flush privileges;
	Query OK, 0 rows affected (0.02 sec)
	 
	mysql> exit
	Bye
	
如果忘记密码,则先停止mysql,然后加上参数skip-grant-tables重新启动mysql server

	root@gaurav:~# /etc/init.d/mysql stop
	 
	Now you should start up the database in the background, via the mysqld_safe command:
	 
	root@gaurav:~# /usr/bin/mysqld_safe --skip-grant-tables &
	[1] 4271
	Starting mysqld daemon with databases from /var/lib/mysql
	mysqld_safe[6763]: started
	
然后登陆mysql,修改密码

	root@gaurav:~$ mysql --user=root mysql
	Enter password:
	 
	mysql> update user set Password=PASSWORD('new-password-here') WHERE User='root';
	Query OK, 2 rows affected (0.04 sec)
	Rows matched: 2  Changed: 2  Warnings: 0
	 
	mysql> flush privileges;
	Query OK, 0 rows affected (0.02 sec)
	 
	mysql> exit
	Bye

最后重启mysql server就可以了。

	root@gaurav:~# /etc/init.d/mysql start
	Starting MySQL database server: mysqld.
	Checking for corrupt, not cleanly closed and upgrade needing tables..
	
用新密码登陆验证下

	root@gaurav:~# mysql --user=root --pass=new-password-here
	Welcome to the MySQL monitor.  Commands end with ; or \g.
	Your MySQL connection id is 5 to server version: 5.0.24a-Debian_4-log
	 
	Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
	 
	mysql> exit
	Bye


转载于:https://www.cnblogs.com/zhwj184/archive/2013/06/02/3119587.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值