Home > Tips and Tricks > #1045 - Access denied for user 'root'@'localhost' (using password: NO) fix

#1045 - Access denied for user 'root'@'localhost' (using password: NO) fix

February 13th, 2008

On a test box running an older version of WAMP, I wanted to correct an installation oversight, the user root with no password. After installing several databases, I decided to change the user root password from no password to some password. After doing so, I immediatly encountered the following error:

#1045 - Access denied for user 'root'@'localhost' (using password: NO)

I was unable to access phpMyAdmin so I found the following command line on http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html#resetting-permissions-windows

The procedure for resetting the MySQL root account's password on Windows is as follows:

  • 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: Start Menu -> Control Panel -> Administrative Tools -> 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.
  • Create a text file and place the following command within it on a single line: SET PASSWORD FOR 'root'@'localhost' = PASSWORD('');
  • Save the file with any name. For this example the file will be C:\mysql-init.txt.
  • Open a console window to get to the DOS command prompt: Start Menu -> Run -> cmd
  • If you installed MySQL to another location, adjust the following commands accordingly. At the DOS command prompt, execute this command: C:\> C:\wamp\mysql\bin>mysqld-nt --init-file=C:\mysql-init.txt

The contents of the file named by the --init-file option are executed at server startup, changing the root password. After the server has started successfully, you should delete C:\mysql-init.txt.

When complete, I stopped and restarted the services. All is operational. Success.

Comments are closed.