Submitted by ricocheting on
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
- 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)
- Change directory to where you installed mysql to:
C:\> cd C:\mysql\bin - Switch to mysql command line:
C:\mysql\bin> mysql -u root mysql - 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
- 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)
- Change directory to where you installed mysql to:
C:\> cd C:\mysql\bin - 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 - 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
January 14, 2011 - 2:08am — Anonymous
Shortcut is autoadded
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.
May 20, 2011 - 10:08am — Anonymous
Resetting the password if you don't remember the original
> mysql -u root mysq
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
The solution for this is:
(note: sometimes you need --defaults-file to specify my.inf)
December 15, 2015 - 5:53pm — ricocheting
Resetting MySQL root password on Mac
Just dealt with this on a friend's Mac OSX 10.10.5 (Yosemite) when he was setting up Kodi with MySQL v5.7.10 and kept getting ERROR 1045 Access denied for user 'root'@'localhost' (using password: NO) where the install root password he was given did not work.
What we had to do to fix the problem
sudo /usr/local/mysql/support-files/mysql.server start --skip-grant-tables
sudo /usr/local/mysql/bin/mysql
USE mysql;
UPDATE `user` SET `authentication_string`=PASSWORD('newpass') WHERE `user`='root';
sudo /usr/local/mysql/bin/mysql -u root -p