How to Change MySQL root password on Windows

Description

Use these instructions if you need change the root password for MySQL on Windows or if you need to add additional new users with general or specific limitations.

Setting a root password for MySQL

  1. Start your command line by going to the Start Menu > Run and typing cmd (or type command if you are using an older version of windows)
  2. Change directory to where you installed mysql to:
    C:\> cd C:\mysql\bin
  3. Switch to mysql command line:
    C:\mysql\bin> mysql -u root mysql
  4. Then set a default password:
    mysql> SET PASSWORD FOR root@localhost=PASSWORD('newpass');
    where "newpass" is the password you want to use

Adding more users

  1. Start your command line by going to the Start Menu > Run and typing cmd (or type command if you are using an older version of windows)
  2. Change directory to where you installed mysql to:
    C:\> cd C:\mysql\bin
  3. Switch to mysql command line (if you have not set a root password remove the -p switch when you type it in):
    C:\mysql\bin> mysql -u root -p mysql
  4. Then then add your new user:
    mysql> CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';
    where "jeffrey" is the username and "mypass" is the password you want to use. You can also limit users to specific database, allow only certain remote hosts to connect all using the GRANT statement. However, that is outside the scope of this tutorial so search for more info on using GRANT if you are interested in those features.

Comments

You don't need to go to c:\mysql\bin, as you will find a command shortcut on the start-> program files in Windows.
However, it is good to have this explanation.

> mysql -u root mysq
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
If you don't remember the original password, you'll get something like the above message.

The solution for this is:
  • stop mysql
  • save the query SET PASSWORD FOR root@localhost=PASSWORD('newpass'); in a text file
  • start mysqld with ---init-file=C:\\mysql-init.txt (or whatever you named the above file)
    (note: sometimes you need --defaults-file to specify my.inf)
source: Resetting the Root Password: Windows Systems