在 MySQL 5.6 中重置 ROOT 密码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21651898/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:00:23  来源:igfitidea点击:

Resetting ROOT password in MySQL 5.6

mysqlwindows-7passwordspassword-recoverymysql-5.6

提问by PM 77-1

I have been following these instructionsfor resetting rootpassword for local installation of MySQL 5.6on Windows 7 laptop.

我一直在按照这些说明重置Windows 7 笔记本电脑本地安装的root密码MySQL 5.6

I stopped the service, created init-file, and ran the following command (as Administrator):

我停止了服务,创建了init-file,并运行了以下命令(以管理员身份):

"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqld" --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.6\my.ini" --init-file=C:\MySQL-misc\mysql-init.txt

I got the following warning:

我收到以下警告

2014-02-08 15:44:10 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2014-02-08 15:44:10 0 [警告] 不推荐使用具有隐式默认值的时间戳。请使用 --explicit_defaults_for_timestamp 服务器选项(有关更多详细信息,请参阅文档)。

Since it's a warning I'm not sure whether I need to fix anything and then redo the process again.

由于这是一个警告,我不确定是否需要修复任何内容,然后再次重做该过程。

Currently the command window is still on and does not accept any input. Should I force-close it or is there anything I can do to complete the process gracefully?

当前命令窗口仍然打开并且不接受任何输入。我应该强制关闭它还是我可以做些什么来优雅地完成这个过程?

UPDATE

更新

I killed the Command window and tried to restart the service. Got an error.

我杀死了命令窗口并尝试重新启动服务。有错误。

Restarted Windows and the service automatically started. The newroot passwordseems to work. I was successfully able to use various functions of Workbench that require the password.

重新启动 Windows,服务自动启动。该root password似乎工作。我成功地使用了需要密码的 Workbench 的各种功能。

So, the warning was indeed just a warning.

所以,警告确实只是警告。

采纳答案by PM 77-1

The issue has been resolved.

问题已解决

As stated in my question I followed instructions from MySQL manual.

正如我的问题中所述,我遵循 MySQL 手册中的说明

The process did not go exactlyas described (and this was the reason for my original post) but it worked nevertheless (see UPDATEsection in my post).

该过程并没有完全按照描述进行(这就是我发布原始帖子的原因),但它仍然有效(请参阅我帖子中的更新部分)。

回答by Timeless

On Windows:

在 Windows 上

0) shut down service mysql56

0) 关闭服务 mysql56

1) go to C:\ProgramData\MySQL\MySQL Server 5.6, note that ProgramDatais a hidden folder

1)转到C:\ProgramData\MySQL\MySQL Server 5.6,注意这ProgramData是一个隐藏文件夹

2) looking for file my.ini, open it and add one line skip-grant-tablesbelow [mysqld],save

2)寻找文件my.ini,打开它并在skip-grant-tables下面添加一行[mysqld],保存

[mysqld]

skip-grant-tables

3) start service mysql56

3)启动服务 mysql56

4) by right, you can access the database, run mysql

4)通过右键,可以访问数据库,运行 mysql

5) and use the query below to update the password

5)并使用下面的查询来更新密码

update mysql.user set password=PASSWORD('NEW PASSWORD') where user='root';

note: for newer version, use authentication_stringinstead of password

注意:对于较新的版本,使用authentication_string代替password

6) shut down the service again, remove the line skip-grant-tablessave it, and start the service again. try to use the password you set to login.

6)再次关闭服务,去掉行skip-grant-tables保存,重新启动服务。尝试使用您设置的密码登录。



On Mac:

在 Mac 上

0) stop the service

0) 停止服务

sudo /usr/local/mysql/support-files/mysql.server stop

1) skip grant table

1) 跳过授权表

sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables

once it's running, don't close it, and open a new terminal window

一旦它运行,不要关闭它,并打开一个新的终端窗口

2) go into mysql terminal

2)进入mysql终端

/usr/local/mysql/bin/mysql -u root

3) update the password

3)更新密码

UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';

for newer version like 5.7, use

对于 5.7 等较新版本,请使用

UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';

4) run FLUSH PRIVILEGES;

4)运行 FLUSH PRIVILEGES;

5) run \qto quit

5)运行\q退出

6) start the mysql server

6)启动mysql服务器

sudo /usr/local/mysql/support-files/mysql.server start

回答by Satishakumar Awati

  • Stop Mysql service by going into Administrative tools > Services
  • Open Start > Run > cmd (Run as administrator)
  • Start the server manually using this line:

    mysqld -P3306 --skip-grant-tables
    
  • In new cmd (Run as administrator) execute :

    mysql -P3306 mysql
    
  • Execute the following query in mysql client:

    update mysql.user set authentication_string=password('new_password') where user='root';
    
  • 通过进入管理工具>服务停止Mysql服务
  • 打开开始>运行>cmd(以管理员身份运行
  • 使用以下行手动启动服务器:

    mysqld -P3306 --skip-grant-tables
    
  • 在新的 cmd(以管理员身份运行)中执行:

    mysql -P3306 mysql
    
  • 在mysql客户端执行以下查询:

    update mysql.user set authentication_string=password('new_password') where user='root';
    

That's it!!

就是这样!!

回答by Poliakoff

Updating this answerregarding to changes at MySQL 5.7:

更新有关 MySQL 5.7 更改的答案

0) shut down service mysql57

0) 关闭服务 mysql57

1) go to C:\ProgramData\MySQL\MySQL Server 5.7, note that ProgramDatais a hidden folder

1)转到C:\ProgramData\MySQL\MySQL Server 5.7,注意这ProgramData是一个隐藏文件夹

2) looking for file my.ini, open it and add one line skip-grant-tablesbelow [mysqld],save

2)寻找文件my.ini,打开它并在skip-grant-tables下面添加一行[mysqld],保存

[mysqld]

skip-grant-tables

3) start service mysql57

3)启动服务 mysql57

4) by right, you can access the database, run mysql

4)通过右键,可以访问数据库,运行mysql

5) and use the query below to update the password

5)并使用下面的查询来更新密码

update mysql.user set authentication_string=password('NEW_PASSWORD') where user='root';

update mysql.user set authentication_string=password('NEW_PASSWORD') where user='root';

6) shut down the service again, remove the line skip-grant-tablessave it, and start the service again. try to use the password you set to login.

6)再次关闭服务,去掉行skip-grant-tables保存,重新启动服务。尝试使用您设置的密码登录。

回答by webDev

In case if you have Xampp installed.

如果您安装了 Xampp。

  1. Goto C:\xampp\mysql\bin
  2. Open my.ini file
  3. Put skip-grant-tablesunder [mysqld]
  4. Goto windows services and stop mysql service
  5. Trigger this command from command prompt C:\xampp\mysql\bin\mysql
  6. Now, reset the root password with the MySQL query update mysql.user set password=PASSWORD('root') where user='root';
  7. Exit the command prompt.
  8. Restart the mysql windows service that was turned off in step 4.
  9. Now you will be able to login to mysql using password as root.
  1. 转到 C:\xampp\mysql\bin
  2. 打开 my.ini 文件
  3. 放在skip-grant-tables下面[mysqld]
  4. 转到 windows 服务并停止 mysql 服务
  5. 从命令提示符触发此命令 C:\xampp\mysql\bin\mysql
  6. 现在,使用 MySQL 查询重置 root 密码 update mysql.user set password=PASSWORD('root') where user='root';
  7. 退出命令提示符。
  8. 重启在步骤4中关闭的mysql windows服务。
  9. 现在您将能够使用密码作为 root 登录到 mysql。

回答by Mohan

For MySQL 5.6 on Windows I had to run this statement to make it work.

对于 Windows 上的 MySQL 5.6,我必须运行此语句才能使其工作。

UPDATE mysql.user
SET Password=PASSWORD('NEW PASSWORD'), 
authentication_String=PASSWORD('NEW PASSWORD')
WHERE User='root';

回答by Mohamed Ayas

First stop mysql server and follow below steps:

首先停止mysql服务器并按照以下步骤操作:

Go to mysql bin directory on cmd i,e. cd C:\ProgramData\MySQL\MySQL Server 5.6\bin(Its a hidden directory)

转到 cmd 上的 mysql bin 目录,即 cd C:\ProgramData\MySQL\MySQL Server 5.6\bin(它是一个隐藏目录)

skip grant tables will allow you enter into mysql

跳过授权表将允许您进入 mysql

  • mysqld.exe --skip-grant-tables
  • mysqld.exe --skip-grant-tables

Open new command prompt or on same command prompt

打开新的命令提示符或在相同的命令提示符下

  • mysql.exe -uroot -p(without any password you can login to mysql)
  • mysql.exe -uroot -p(无需任何密码即可登录mysql)

run below query to change mysql root password

运行以下查询以更改 mysql root 密码

  • UPDATE mysql.user set password=password('root password') WHERE user='root';
  • flush privileges
  • UPDATE mysql.user set password=password('root password') WHERE user='root';
  • flush privileges

Thats it, Restart mysql and good to go with new password..!!

就是这样,重新启动 mysql 并使用新密码很好.. !!

回答by Cris

Without editing mi.ini:

无需编辑 mi.ini:

service mysql stop
mysqld_safe --skip-grant-tables

on a separate ssh session:

在单独的 ssh 会话中:

update mysql.user set password=PASSWORD('NEW PASSWORD') where user='root';

no need to flush privileges, just restart the server

无需刷新权限,只需重新启动服务器

回答by JesusIniesta

If you are getting this error: mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.when attempting to reset your root password. You might try:

如果您收到此错误:mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.尝试重置 root 密码时。你可以试试:

sudo service mysql stop
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables & 
mysql -uroot
update mysql.user set authentication_string=password('your_password') where user='root';
flush privileges;
quit
sudo killall mysql
sudo service mysql start
mysql -u root -pyour_password

Tested in MySQL 5.7 running in Ubuntu 18.04

在运行于 Ubuntu 18.04 的 MySQL 5.7 中测试