How do I reset the MySQL password under Windows?

2

When trying to restart my MySQL password I get the following output in the console (this is also the input that caused the output):

C:>"C:\MySQL\bin\mysqld" --console --init-file=C:\mysql--init.txt

111008 23:42:48 [Note] Plugin 'FEDERATED' is disabled.
111008 23:42:48 InnoDB: The InnoDB memory heap is disabled
111008 23:42:48 InnoDB: Mutexes and rw_locks use Windows interlocked functions
111008 23:42:48 InnoDB: Compressed tables use zlib 1.2.3
111008 23:42:48 InnoDB: Initializing buffer pool, size = 45.0M
111008 23:42:48 InnoDB: Completed initialization of buffer pool
InnoDB: Error: log file .\ib_logfile0 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 24117248 bytes!
111008 23:42:48 [ERROR] Plugin 'InnoDB' init function returned error.
111008 23:42:48 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.

111008 23:42:48 [ERROR] Unknown/unsupported storage engine: INNODB 
111008 23:42:48 [ERROR] Aborting

111008 23:42:48 [Note] C:\MySQL\bin\mysqld: Shutdown complete

Dynamic

Posted 2011-10-03T18:56:15.763

Reputation: 381

@random: I have added the info. – Dynamic – 2011-10-03T19:35:50.707

Number the steps, I am far to tired, to figure out which line is suppose to be step 6. – Ramhound – 2011-10-03T19:41:25.927

@Ramhound: The entire thing is step 6. – Dynamic – 2011-10-03T19:42:04.880

So have you created the init file and saved it there? What happens when you execute C:\mysql\bin\mysqld --init-file=C:\\mysql-init.txt? (Note that your edit only copied step 6 in there, you still haven't told us what you've tried!) – slhck – 2011-10-03T19:44:59.117

@slhck: I've tried every step before step six, then I get stopped there. – Dynamic – 2011-10-03T19:50:14.183

Answers

2

If you have followed the step in the manual you just need to execute the command:

C:\> C:\mysql\bin\mysqld --init-file=C:\\mysql-init.txt

Which automatically will reset the password (because you wrote the file with the command to do it (step 3)).

If this command doesn't work just execute the other command:

C:\> "C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld.exe"
        --defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.5\\my.ini"
        --init-file=C:\\mysql-init.txt

DavidEG

Posted 2011-10-03T18:56:15.763

Reputation: 316

Where do I execute this? – Dynamic – 2011-10-03T19:49:47.473

"From the Start menu, select Run, then enter cmd as the command to be run" after that you will see the cmd window and you have to put the command in. – DavidEG – 2011-10-03T19:55:45.330

I executed the first command. I got the following message: :\\mysql-init.txt 111003 16:20:43 [Warning] '--default-character-set' is deprecated and will be re moved in a future release. Please use '--character-set-server' instead. – Dynamic – 2011-10-03T20:21:51.850

So use the suggested command instead. – Ramhound – 2011-10-05T13:21:21.883

1

Manual says:

C.5.4.1.1. Resetting the Root Password: Windows Systems On Windows, use the following procedure to reset the password for all MySQL root accounts:

  1. Log on to your system as Administrator.
  2. 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. If your server is not running as a service, you may need to use the Task Manager to force it to stop.
  3. Create a text file containing the following statements. Replace the password with the password that you want to use.

    UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root'; FLUSH PRIVILEGES;
    

    Write the UPDATE and FLUSH statements each on a single line. The UPDATE statement resets the password for all root accounts, and the FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.

  4. Save the file. For this example, the file will be named C:\mysql-init.txt.
  5. Open a console window to get to the command prompt: From the Start menu, select Run, then enter cmd as the command to be run.
  6. Start the MySQL server with the special --init-file option (notice that the backslash in the option value is doubled):

    C:\> C:\mysql\bin\mysqld-nt --init-file=C:\\mysql-init.txt 
    

    If you installed MySQL to a location other than C:\mysql, adjust the command accordingly. The server executes the contents of the file named by the --init-file option at startup, changing each root account password. You can also add the --console option to the command if you want server output to appear in the console window rather than in a log file. If you installed MySQL using the MySQL Installation Wizard, you may need to specify a --defaults-file option:

    C:\> "C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe" --defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini" --init-file=C:\\mysql-init.txt 
    

The appropriate --defaults-file setting can be found using the Services Manager: From the Start menu, select Control Panel, then Administrative Tools, then Services. Find the MySQL service in the list, right-click it, and choose the Properties option. The Path to executable field contains the --defaults-file setting. 7. After the server has started successfully, delete C:\mysql-init.txt.

So first you have to create file as stated in point 3 and then, using a command line (Start->Run->CMD(ENTER), run mysqld-nt.exe with --init-file param pointing to that file. Remember to use full path both for mysqld-nt.exe and your created file.

Marco

Posted 2011-10-03T18:56:15.763

Reputation: 431

Ok, so how do I run mysqld-nt.exe? – Dynamic – 2011-10-03T19:54:43.147

Did you find mysqld-nt.exe installation directory? If yes, call it MYSQLDIR. Then run Start->Run->cmd and press ENTER. In the black window that appears, write "MYSQLDIR\mysqld-nt.exe" --init-file="full_name_txt_file_created_in_point_3" and press ENTER – Marco – 2011-10-03T19:57:24.797

I found mysqld.exe. Is the directory you talking about the one that holds this? – Dynamic – 2011-10-03T20:13:10.987

yes, the one I called MYSQLDIR is the one in which resides mysqld-nt.exe – Marco – 2011-10-03T21:30:31.100

I tried this with no luck. – Dynamic – 2011-10-03T22:59:30.320

@perl.j: did you get some error? – Marco – 2011-10-04T05:50:40.413

I got the following error :\\mysql-init.txt 111003 16:20:43 [Warning] '--default-character-set' is deprecated and will be re moved in a future release. Please use '--character-set-server' instead – Dynamic – 2011-10-04T10:32:39.553

@perl.j: take a look at this link, read it carefully till the end and you'll solve your problem

– Marco – 2011-10-04T10:37:16.047

I think I did everything right... but my password is still denied even though it was in my init file. – Dynamic – 2011-10-04T22:42:36.623

The problem is his innodb_log_file_size. – Aaron Brown – 2011-10-19T03:59:08.853

1

I answered a question just like this in the DBA StackExchange back on Sep 26, 2011.

This person accepted my answer.

It is like a hack of my.ini and it should work for you.

UPDATE 2011-10-19 07:12 EDT

All you have to do is delete ib_logfile0 and ib_logifle1, and mysqld will cause InnoDB to regenerate the two innodb log files.

I wish had seen the error log earlier. All this time I keep helping you solve the grants issues.

RolandoMySQLDBA

Posted 2011-10-03T18:56:15.763

Reputation: 2 675

I get an error: system error 1067 has occurred when trying to start the MySQL service. – Dynamic – 2011-10-05T19:09:20.663

What does the error log say happened ??? – RolandoMySQLDBA – 2011-10-05T19:28:27.673

Error log? What error log? Please I'm very new to this. – Dynamic – 2011-10-05T20:29:07.210

By default, wherever the datadir of mysql is, there is a default error log which is usually hostname.err. – RolandoMySQLDBA – 2011-10-05T20:48:36.857

And where is the datadir usually placed? – Dynamic – 2011-10-06T00:58:50.833

If you used the MSI wizard to install, then it would be C:\Program Files\MySQL\MySQL Server 5.1\data by default. – RolandoMySQLDBA – 2011-10-06T01:02:22.283

It's not there... anywhere else? – Dynamic – 2011-10-06T01:03:30.423

1

In your case, before you can even reset the password, you need to fix the start up issue.

Note the first error listed in MySQL error log:

InnoDB: Error: log file .\ib_logfile0 is of different size 0 5242880 bytes
InnoDB: than specified in the .cnf file 0 24117248 bytes!

This means that you may have copied your database files from another location or you have edited my.cnf settings and they no longer match the real ib_logfile0 file size. Focus on this issue first.

dabest1

Posted 2011-10-03T18:56:15.763

Reputation: 972

I wish I could upvote this 3 times because it's the only answer in this thread that is correct. Did anyone else even read the error message? – Aaron Brown – 2011-10-19T03:58:05.690

Thanks @AaronBrown! It looks like the question was heavily edited, so that would explain the answers from other people. – dabest1 – 2011-10-19T10:50:10.250

oops, you're right. My apologies to the other posters. – Aaron Brown – 2011-10-21T20:02:46.880