如何在 MySQL 8.0.11 中重置 root 密码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50691977/
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
How to reset the root password in MySQL 8.0.11?
提问by Mangue Sutcliff
I have actually lost my root password and I need to change it. I follow these steps :
我实际上丢失了我的 root 密码,我需要更改它。我按照以下步骤操作:
Step # 1: Stop the MySQL server process.
Step # 2: Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for a password.
Step # 3: Connect to the MySQL server as the root user.
第 1 步:停止 MySQL 服务器进程。
第 2 步:使用 --skip-grant-tables 选项启动 MySQL (mysqld) 服务器/守护进程,这样它就不会提示输入密码。
第 3 步:以 root 用户身份连接到 MySQL 服务器。
that we can found on these website : https://www.howtoforge.com/setting-changing-resetting-mysql-root-passwords#recover-mysql-root-password
我们可以在这些网站上找到:https: //www.howtoforge.com/setting-changed-resetting-mysql-root-passwords#recover-mysql-root-password
mysql> use mysql;
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD("TOOR");
mysql> flush privileges;
mysql> quit
First error, so I tried :
第一个错误,所以我尝试:
mysql> use mysql;
mysql> update user set password=PASSWORD("TOOR") where User='root';
mysql> flush privileges;
mysql> quit
Always the same error said :
总是同样的错误说:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '("TOO
R") WHERE User='root'' at line 1
How can I resolve this?
我该如何解决这个问题?
回答by Hyman Chern
as heresays:
正如这里所说:
This function was removed in MySQL 8.0.11
该功能在 MySQL 8.0.11 中被移除
1.if you in skip-grant-tables mode
in mysqld_safe:
1.如果您
在mysqld_safe中处于skip-grant-tables模式:
UPDATE mysql.user SET authentication_string=null WHERE User='root';
FLUSH PRIVILEGES;
exit;
and then, in terminal:
然后,在终端中:
mysql -u root
in mysql:
在 mysql 中:
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';
2.not in skip-grant-tables mode
just in mysql:
2.不是
在mysql中的skip-grant-tables模式:
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';
回答by Jitesh Middha
Try this:
尝试这个:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newPasswd';
回答by Ashit
Step 1: Create a new file in your root directory( e.g C:) Step 2: Write this ALTER USER 'root'@'localhost' IDENTIFIED BY 'abc'and save it Step 3: If your Mysql service is already running, please stop this and open your CMD Step 4: Go to your Mysql installation directory (e.g C:\Program Files\MySQL\MySQL Server 8.0\bin) and type this command
第 1 步:在您的根目录(例如 C:)中创建一个新文件 第 2 步:写入此ALTER USER 'root'@'localhost' IDENTIFIED BY 'abc'并保存第 3 步:如果您的 Mysql 服务已经在运行,请停止此操作并打开您的 CMD 第 4 步:转到您的 Mysql 安装目录(例如 C:\Program Files\MySQL\MySQL Server 8.0\bin)并键入此命令
mysql --init-file=C:/init.sql
Step 5: Execute this command and you are good to go :)
第 5 步:执行此命令,您就可以开始了 :)
Refer this video for more clarification : https://www.youtube.com/watch?v=LsdV-7dFOhk
请参阅此视频以获取更多说明:https: //www.youtube.com/watch?v=LsdV- 7dFOhk
回答by chaithanya varma
Using SQLYog you can execute commands
使用 SQLYog 您可以执行命令
User Creation
CREATE USER 'tester'@'localhost' IDENTIFIED BY 'Pass123#d'
Authorization
GRANT ALL PRIVILEGES ON sakila.* TO 'tester'@'localhost'
Changing Password in MySQL 8.0
ALTER USER 'tester'@'localhost' IDENTIFIED BY 'Pass123#d';
or if u know the authentication_string directly set it to update
UPDATE mysql.user SET authentication_string='*F9B62579F38BE95639ACB009D79427F2D617158F' WHERE USER='root'
Changing password in lower versions of mysql
GRANT USAGE ON *.\* TO 'tester'@'localhost' IDENTIFIED BY 'Pass123#d' SET PASSWORD FOR 'tester'@'localhost' = PASSWORD('Pass123#d');
用户创建
CREATE USER 'tester'@'localhost' IDENTIFIED BY 'Pass123#d'
授权
GRANT ALL PRIVILEGES ON sakila.* TO 'tester'@'localhost'
在 MySQL 8.0 中更改密码
ALTER USER 'tester'@'localhost' IDENTIFIED BY 'Pass123#d';
或者如果您知道 authentication_string 直接将其设置为更新
UPDATE mysql.user SET authentication_string='*F9B62579F38BE95639ACB009D79427F2D617158F' WHERE USER='root'
在较低版本的mysql中更改密码
GRANT USAGE ON *.\* TO 'tester'@'localhost' IDENTIFIED BY 'Pass123#d' SET PASSWORD FOR 'tester'@'localhost' = PASSWORD('Pass123#d');