您的位置:首页 > 运维架构 > Linux

mysql(windows or linux)忘记密码

2014-08-13 18:08 369 查看
提示: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、

1 在服务里面先把mysql服务停止

2 然后在C:\Program Files\MySQL\MySQL Server 5.6 下找到my.ini 文件,my*.ini文件

并在[mysqld]下面添加参数 skip-grant-tables 保存

3 启动mysql服务

4登陆mysql此时不需要密码

5 可以查看mysql数据库表中的权限 但是按照网上查询处理的方法 修改密码 报错:skip-grant-tables启动 不能修改密码

update user set Password='' where Host='localhost';将密码置为空

6 关闭mysql服务 修改my.ini文件 将 skip-grant-tables 参数注释掉 保存

7 启动服务(此时也不需要密码已将密码置空)

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

[b]Files\MySQL\MySQL Server 5.6\my.ini" --console --skip-grant-tables
[/b]

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

若以上方法不可用欢迎截图留言,大家一起解决
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: