MySQL 重置mysql工作台root密码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8232039/
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 21:47:39  来源:igfitidea点击:

resetting mysql workbench root password

mysql

提问by droidus

I am trying to reset the root password for mySQL Workbench since I forgot it. I was reviewing some online tutorials of how to do this, and they all speak of a "bin" folder. I went to the program folder, and didn't see a bin folder. How do I do this?

我正在尝试重置 mySQL Workbench 的 root 密码,因为我忘记了它。我正在查看一些有关如何执行此操作的在线教程,它们都提到了“bin”文件夹。我去了程序文件夹,没有看到bin文件夹。我该怎么做呢?

回答by hovanessyan

Reset MySQL root password official documentationhas cases for Windows and Unix systems, and a "generic" instruction at the end of the document. Hope that helps.

重置 MySQL 根密码官方文档有针对 Windows 和 Unix 系统的案例,文档末尾有“通用”说明。希望有帮助。

回答by Shaun Luttin

Reset MySQL Root Password from PowerShell

从 PowerShell 重置 MySQL 根密码

1. Stop the MySQL service and process.

1、停止MySQL服务和进程。

spsv mysql*
kill -f -Pro mysqld -ErrorA Ignore

2. Create a temporary init file

2.创建一个临时的init文件

ri C:\temp.txt
ni -t f C:\temp.txt 
ac C:\temp.txt "UPDATE mysql.user SET Password=PASSWORD('4321') WHERE User='root';"
ac C:\temp.txt "FLUSH PRIVILEGES;"

3. Get the location of the MySQL defaults-file.

3. 获取 MySQL 默认文件的位置。

$defaultsFile = (gci -r -Path "C:\ProgramData\MySQL" -include my.ini).FullName

4. Change dir to MySQL bin.

4. 将目录更改为 MySQL bin。

cd "C:\Program Files\MySQL\MySQL Server*\bin"

5. Run mysqld with the password reset.

5. 运行 mysqld 并重置密码。

& .\mysqld.exe --defaults-file="$defaultsFile" --init-file="C:\temp.txt"

6. Kill and Restart MySQLD (in a new PowerShell prompt).

6. 杀死并重新启动 MySQLD(在新的 PowerShell 提示符中)。

ps mysqld | kill -f
sasv "MySql*"

7. Return to the initial prompt and test

7.返回初始提示并测试

& .\mysql -u root -p4321
\q

Notes

笔记

  1. We cannot do anything until we stop MySql completely.
  2. Create this in C:\, then add reset password commands; riremoves any existing temp.txt file.
  3. You can retrieve this path through the Service Control Manager or use (gwmi win32_service | ?{$_.Name -like 'mysql*'} | select -First 1).PathName.
  4. The *in the path means that we don't have to know our version number.
  5. The &makes PowerShell run the exelike the command line does. Once you run this, PowerShell will appear to hang - that's because it's running the mysqldprocess.
  6. We need to kill in another process, because the existing console is busy.
  7. Return to the initial console, because it's already at bin. After the test, you should see mysql>. Use \qto quit.
  1. 在我们完全停止 MySql 之前,我们什么也做不了。
  2. 在 中创建它C:\,然后添加重置密码命令;ri删除任何现有的 temp.txt 文件。
  3. 您可以通过服务控制管理器或使用(gwmi win32_service | ?{$_.Name -like 'mysql*'} | select -First 1).PathName.
  4. *路径的手段,我们并不需要知道我们的版本号。
  5. &使得 PowerShellexe像命令行一样运行。运行此命令后,PowerShell 将显示为挂起 - 那是因为它正在运行该mysqld进程。
  6. 我们需要在另一个进程中杀死,因为现有的控制台很忙。
  7. 返回初始控制台,因为它已经在bin. 测试后,您应该看到mysql>. 使用\q戒烟。

See Also

也可以看看

http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

回答by yoyodunno

Hey if you are on Windows 7 like me you will find the MySQL executables here: C:\Program Files\MySQL\MySQL Server 5.5\bin . I used mysqld.exe, because mysqld-nt.exe doesn't exist anymore in newer versions of MySQL.

嘿,如果你像我一样使用 Windows 7,你会在这里找到 MySQL 可执行文件: C:\Program Files\MySQL\MySQL Server 5.5\bin 。我使用了 mysqld.exe,因为 mysqld-nt.exe 在较新版本的 MySQL 中不再存在。

After following the instructions in the documentation you should have a command similar to this: C:\Program Files\MySQL\MySQL Server 5.5\bin>mysqld.exe --defaults-file="C:\Program Files\MySQL\MySQL Server 5.5\my-medium.ini" --init-file=C:\mysql-initRootPass.txt

按照文档中的说明操作后,您应该有一个类似于以下的命令:C:\Program Files\MySQL\MySQL Server 5.5\bin>mysqld.exe --defaults-file="C:\Program Files\MySQL\MySQL Server 5.5\my-medium.ini" --init-file=C:\mysql-initRootPass.txt

Note: make sure you run the CMD.exe as Administrator. For the most part that fixed it for me.

注意:确保以管理员身份运行 CMD.exe。在很大程度上为我修复了它。