Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resetting mysql workbench root password

Tags:

mysql

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?

like image 929
droidus Avatar asked Nov 22 '11 18:11

droidus


People also ask

What do I do if I forgot my MySQL root password windows?

Log on to your system as Administrator. Stop the MySQL server if it is running. For a server that is running as a Windows service, go to the Services manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list and stop it.


1 Answers

Reset MySQL Root Password from PowerShell

1. Stop the MySQL service and process.

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

2. Create a temporary init file

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.

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

4. Change dir to MySQL bin.

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

5. Run mysqld with the password reset.

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

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

ps mysqld | kill -f
sasv "MySql*"

7. Return to the initial prompt and test

& .\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; ri removes 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 exe like the command line does. Once you run this, PowerShell will appear to hang - that's because it's running the mysqld process.
  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 \q to quit.

See Also

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

like image 146
Shaun Luttin Avatar answered Sep 30 '22 10:09

Shaun Luttin