How do I reset the MySQL password under Windows?

12,488

Solution 1

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

Solution 2

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.

Solution 3

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.

Solution 4

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.

Share:
12,488

Related videos on Youtube

Dynamic
Author by

Dynamic

Updated on September 18, 2022

Comments

  • Dynamic
    Dynamic almost 2 years

    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
      Dynamic over 12 years
      @random: I have added the info.
    • Ramhound
      Ramhound over 12 years
      Number the steps, I am far to tired, to figure out which line is suppose to be step 6.
    • Dynamic
      Dynamic over 12 years
      @Ramhound: The entire thing is step 6.
    • slhck
      slhck over 12 years
      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!)
    • Dynamic
      Dynamic over 12 years
      @slhck: I've tried every step before step six, then I get stopped there.
  • Dynamic
    Dynamic over 12 years
    Where do I execute this?
  • Dynamic
    Dynamic over 12 years
    Ok, so how do I run mysqld-nt.exe?
  • DavidEG
    DavidEG over 12 years
    "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.
  • Dynamic
    Dynamic over 12 years
    I found mysqld.exe. Is the directory you talking about the one that holds this?
  • Dynamic
    Dynamic over 12 years
    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
    Dynamic over 12 years
    I tried this with no luck.
  • Marco
    Marco over 12 years
    @perl.j: did you get some error?
  • Marco
    Marco over 12 years
    @perl.j: take a look at this link, read it carefully till the end and you'll solve your problem
  • Dynamic
    Dynamic over 12 years
    I think I did everything right... but my password is still denied even though it was in my init file.
  • Ramhound
    Ramhound over 12 years
    So use the suggested command instead.
  • Dynamic
    Dynamic over 12 years
    I get an error: system error 1067 has occurred when trying to start the MySQL service.
  • RolandoMySQLDBA
    RolandoMySQLDBA over 12 years
    What does the error log say happened ???
  • Dynamic
    Dynamic over 12 years
    Error log? What error log? Please I'm very new to this.
  • RolandoMySQLDBA
    RolandoMySQLDBA over 12 years
    By default, wherever the datadir of mysql is, there is a default error log which is usually hostname.err.
  • Dynamic
    Dynamic over 12 years
    And where is the datadir usually placed?
  • RolandoMySQLDBA
    RolandoMySQLDBA over 12 years
    If you used the MSI wizard to install, then it would be C:\Program Files\MySQL\MySQL Server 5.1\data by default.
  • Dynamic
    Dynamic over 12 years
    It's not there... anywhere else?
  • Aaron Brown
    Aaron Brown over 12 years
    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
    Aaron Brown over 12 years
    The problem is his innodb_log_file_size.
  • dabest1
    dabest1 over 12 years
    Thanks @AaronBrown! It looks like the question was heavily edited, so that would explain the answers from other people.
  • Aaron Brown
    Aaron Brown over 12 years
    oops, you're right. My apologies to the other posters.