• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

MySQL密码丢掉解决和密码重置

mysql 搞代码 7年前 (2018-06-05) 138次浏览 已收录 0个评论

mysql密码丢失解决和密码重置

这个MySQL有点怪啊,突然间用原账号就登陆不上了(具体原因不详,有知道的告诉我);所以决定修改下原密码。
1.停掉MySQL,然后用无权限验证的方式重新启动MySQL 命令:
Linux下,运行 /usr/local/mysql/bin/mysqld_safe –skip-grant-tables &
Windows下,在命令行下运行 X:/MySQL/bin/mysqld –skip-grant-tables
2.在命令行下用,mysql -u -root登陆
3.修改下密码吧,一位博主(http://blog.chinaunix.net/u/29134/showart_373855.html)写的方法比较全,我就不罗嗦了。三种方法任何一个都行
新手在这个上往往容易范错误,导致不能进入MYSQL,整得非常郁闷。
我来做几个例子相信很快就明白了 。
1、原来的密码是123456
C:/>type mysql5.bat
@echo off
mysql -uroot -p123456 -P3306
正确的修改MYSQL用户密码的格式是:
我们这里用
用户:root(可以换成其他的)
密码:woshiduide
来演示新密码。

C:/>mysqladmin -uroot -p password woshiduide
Enter password: ******
于是修改成功。
注意PASSWORD关键字后面的空格

有好多人是这样修改的:
C:/>mysqladmin -uroot -p password ‘woshiduide’
Enter password: ******

C:/>mysqladmin -uroot -p password ‘woshiduide’
Enter password: *********
Warning: single quotes were not trimmed from the password by your command
line client, as you might have expected.

而这个时候真正的密码是’woshiduide’

C:/>mysql -uroot -p’woshiduide’
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 18
Server version: 5.1.17-beta-community-nt-debug MySQL Community Server (GPL)

Type ‘help;’ or ‘/h’ for help. Type ‘/c’ to clear the buffer.

mysql>

而新手往往这样:
C:/>mysql -uroot -pwoshiduide
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: Y
ES)
所以非常郁闷,BAIDU、GOOGLE的搜了一大堆。

我现在把密码改回去。
C:/>mysqladmin -uroot -p’woshiduide’ password 123456

2、还有就是可以直接进入MYSQL,然后修改密码。

mysql> use mysql
Database changed
mysql> update user set PASSWORD = PASSWORD(‘woshiduide’) where USER=’root’ and H
OST=’localhost’;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;

mysql> exit
Bye

C:/>mysql -uroot -pwoshiduide
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 23
Server version: 5.1.17-beta-community-nt-debug MySQL Community Server (GPL)

Type ‘help;’ or ‘/h’ for help. Type ‘/c’ to clear the buffer.

mysql>
Query OK, 0 rows affected (0.02 sec)
3、还有一种就是用SET PASSWORD 命令修改:

C:/>mysql5.bat
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 8
Server version: 5.1.17-beta-community-nt-debug-log MySQL Community Server (GPL)

Type ‘help;’ or ‘/h’ for help. Type ‘/c’ to clear the buffer.

mysql> set password for root@’localhost’ = password(‘woshiduide’);
Query OK, 0 rows affected (0.02 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.09 sec)

mysql> exit
Bye
4、GRANT 也可以,不过这里不介绍。因为涉及到权限的问题。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:MySQL密码丢掉解决和密码重置

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

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

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