0

昨天一切正常。今天,当我启动 mysql 时,它开始给我以下错误消息

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

我不知道它何时以及如何设置密码。

现在我正在尝试设置密码,但它没有更新它。

我正在使用以下步骤来恢复密码。

  1. 停止 Mysql 服务
  2. 在 cmd 中写入:

C:\Program Files\MySQL\MySQL Server 5.5>mysqld.exe --defaults-file="my.ini" --init-file="d:\mysql-init.txt" --console

它开始向我显示进度,但在此消息后停止响应

160504 18:01:54 [Note] Server socket created on IP: '0.0.0.0'.
160504 18:01:54 [Note] Event Scheduler: Loaded 0 events
160504 18:01:54 [Note] mysqld.exe: ready for connections.
Version: '5.5.38'  socket: ''  port: 3306  MySQL Community Server (GPL)

我等了超过 10 分钟,但此后没有显示任何进展..

请指导我如何解决这个问题。

谢谢

4

3 回答 3

2

停止mysql服务

编辑my.ini文件或my.cnf文件

在ini文件中找到[mysqld]section,在section后面直接添加这一行[mysqld]

skip-grant-tables

重启mysql服务。

打开 MySQL 控制台

现在我们要重置root用户的密码,当然这可以用来重置任何用户的密码。

在 mysql> 命令提示符处输入以下 2 个命令,每行末尾有一个分号,每行后按 ENTER 以向 mysql 发出命令。

MYSQL 5.7 之前的版本

UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;

发布 MYSQL 5.7 版的列名已更改

UPDATE mysql.user SET authentication_string=PASSWORD('MyNewPass') WHERE User='root';
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;

请注意,更新可能会报告它已更新多行,因为实际上有 3 个用户帐户的用户 ID 为“root”,每个帐户具有不同的域,即 127.0.0.1、localhost 和 ::1

Now enter quit at the mysql command prompt to exit mysql.

Stop the mysql service

Edit the my.ini file or my.cnf file

Find the {mysqld] section in the ini file and Remove the skip-grant-tables parameter we added earlier.

DO NOT Leave this parameter in the ini file its a HUGH security hole.

Restart the mysql service.

You should now be able to login with phpmyadmin using the userid 'root' and the new password you have just set for that user.

于 2016-05-04T13:32:10.247 回答
1

按照步骤更改 mySQL root 密码。

1) 以管理员身份登录服务器。

2) 停止 MySQL 服务或从任务管理器中终止它 [mysqld-nt.exe] [如果无法从 services.msc 中工作]。

3) 创建一个包含以下语句的文本文件:

UPDATE mysql.user SET Password=PASSWORD('test@123') WHERE User='root'; 同花顺特权;

4) 保存文件。对于此示例,该文件将命名为 C:\mysql-init.txt。

5) 进入命令提示符:使用 --init-file 选项启动 MySQL 服务器。

6) C:> C:\mysql\bin\mysqld-nt --init-file=C:\mysql-init.txt

于 2016-05-04T13:10:49.980 回答
1
  1. 停止mysql服务

    /etc/init.d/mysql 停止

  2. 跳过 mysql 权限

    /usr/bin/mysqld_safe --user=mysql --skip-grant-tables

  3. 打开cmd并写入

    mysql

  4. 现在让我们通过以下命令使用我们的数据库:

    使用 MY_DATABASE_NAME;

  5. 使用以下命令更新 root 用户的字段密码:

    更新用户 SET Password=PASSWORD('ourpassword') WHERE user='root';

  6. 退出命令。

    出口

  7. 启动一个新的数据库会话。

    mysql -u 根目录 -p

于 2016-05-04T13:11:04.583 回答