mysql(windows or linux)忘记密码

提示:1045 access denied for user 'root'@'localhost' using password yes

连接数据库时候弹出这个,然后又忘记密码了请看

转载请注明出处http://blog.csdn.net/yc7369

曾经由于这个问题找了各种方法,各种行不通,最后将可用方法进行了记录,今日将其整理,以高来者

Linux:

先跳转到mysql文件夹下
#mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 
# mysql -u root mysql    
mysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’; 
mysql> FLUSH PRIVILEGES; 
mysql> quit 
# /etc/init.d/mysql restart 
# mysql -uroot -p 
Enter password: <输入新设的密码
newpassword> 
mysql> 

 

Windows:

法1、

在服务里面先把mysql服务停止
然后在
C:\Program Files\MySQL\MySQL Server 5.6 下找到my.ini 文件,my*.ini文件
并在[mysqld]下面添加参数 skip-grant-tables 保存
启动
mysql服务 
4登陆
mysql此时不需要密码
可以查看
mysql数据库表中的权限 但是按照网上查询处理的方法 修改密码 报错:skip-grant-tables启动 不能修改密码
update user set Password='' where Host='localhost';将密码置为空

关闭
mysql服务  修改my.ini文件  将 skip-grant-tables 参数注释掉 保存 
启动服务(此时也不需要密码已将密码置空)

grant all on *.* to 'root'@'localhost' identified by '123456';
设置成功  退出 重新登陆 成功

 

有的朋友说法1对他PC好像没生效,这个我也遇到过,我们可以借鉴linux的方式,不过前面得新增一些步骤,此法亲测可用,由版主ACMAIN_CHM开放,yc整理

法2、

WINDOWS的命令行了(‘DOS’ 下),切换到你的MySQL bin目录下。 比如我的是 C:\Program Files\MySQL\MySQL Server 5.1\bin
然后敲下面的粗体的命令。注意你的my.ini位置。

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysqld  --defaults-file="C:\Program
Files\MySQL\MySQL Server 5.6\my.ini" --console --skip-grant-tables

090515 22:06:09 [Warning] The syntax '--log' is deprecated and will be removed i
n MySQL 7.0. Please use '--general_log'/'--general_log_file' instead.
090515 22:06:09 [Warning] The syntax '--log_slow_queries' is deprecated and will
 be removed in MySQL 7.0. Please use '--slow_query_log'/'--slow_query_log_file'
instead.
090515 22:06:09 [Warning] The syntax '--log' is deprecated and will be removed i
n MySQL 7.0. Please use '--general_log'/'--general_log_file' instead.
090515 22:06:09 [Warning] The syntax '--log_slow_queries' is deprecated and will
 be removed in MySQL 7.0. Please use '--slow_query_log'/'--slow_query_log_file'
instead.
090515 22:06:09 [ERROR] The update log is no longer supported by MySQL in versio
n 5.0 and above. It is replaced by the binary log. Now starting MySQL with --log
-bin='' instead.
090515 22:06:09  InnoDB: Started; log sequence number 0 324221
090515 22:06:09 [Note] mysqld: ready for connections.
Version: '5.6-community-log'  socket: ''  port: 3306  MySQL Community Server
(GPL)

看到这个结果就说明MySQL已经起来了。
再开一个DOS窗口,同样切到mysql bin目录下,
C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -uroot mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 http://blog.csdn.net/yc7369


转载请注明出处http://blog.csdn.net/yc7369


若以上方法不可用欢迎截图留言,大家一起解决

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值