snippetsqlMinor
How to recover a lost password in MySQL 5.7.11? (for Windows)
Viewed 0 times
lostpasswordrecovermysqlforwindowshow
Problem
I am running MySQL 5.7.11 on Windows 10
I am unable to login to root through the command line client since I lost my password.
How do I change/reset the old password?
Please help, and thanks in advance.
I am unable to login to root through the command line client since I lost my password.
How do I change/reset the old password?
Please help, and thanks in advance.
Solution
If you installed MySQL as a service, you need the following:
STEP 01
Open Windows Command Line as Administrator and run
STEP 02
Add this to
STEP 03
You should be logged into mysql
STEP 04
Suppose you want root@localhost's password to be
STEP 05
STEP 06
Remove the
STEP 07
STEP 08
This should prompt you for the password. Enter new password and you should be in.
ALTERNATIVE
Instead of creating
You should now be inside mysql without a password. Next run this
Back at the command line, shutdown mysql like this:
Now, you start MySQL57 Service back up
STEP 01
Open Windows Command Line as Administrator and run
C:\> net stop mysqlSTEP 02
Add this to
C:\Program Files (x86)\MySQL\MySQL 5.7\my.ini under the [mysqld] group header[mysqld]
skip-grant-tablesSTEP 03
C:\> net start mysql
C:\> mysqlYou should be logged into mysql
STEP 04
Suppose you want root@localhost's password to be
hello, run thisUPDATE mysql.user SET password=password('hello') where user='root' and host='localhost';
exitSTEP 05
C:\> net stop mysqlSTEP 06
Remove the
skip-grant-tables option from the my.iniSTEP 07
C:\> net start mysqlSTEP 08
C:\> mysql -uroot -pThis should prompt you for the password. Enter new password and you should be in.
ALTERNATIVE
Instead of creating
my.ini, do the following after you have shutdown MySQLC:\> cd C:\Program Files\MySQL\MySQL Server 5.7\bin
C:\> start mysqld.exe --skip-grant-tables
C:\> mysqlYou should now be inside mysql without a password. Next run this
UPDATE mysql.user SET password=password('hello') where user='root' and host='localhost';
exitBack at the command line, shutdown mysql like this:
C:\> mysqladmin shutdownNow, you start MySQL57 Service back up
Code Snippets
C:\> net stop mysql[mysqld]
skip-grant-tablesC:\> net start mysql
C:\> mysqlUPDATE mysql.user SET password=password('hello') where user='root' and host='localhost';
exitC:\> net stop mysqlContext
StackExchange Database Administrators Q#143148, answer score: 3
Revisions (0)
No revisions yet.