In order to reset the password on a Windows machine, log in to your computer using an Administrator account, go to Start, type services and open the utility. Locate the MySQL service in the provided list and then press the Stop button. If the server is not running as a service, you may need to use Task Manager (Alt + Ctrl + Delete) to stop it. On your (C:) drive create a text file (you can use Notepad) containing the following statement:
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;
After that, save the file as mysql-init.txt, open the Start menu, type cmd and open the tool. Type C:\> C:\mysql\bin\mysqld-nt --init-file=C:\\mysql-init.txt
and hit Enter. Instead of C:\mysql
, you will need to use the path to the directory where you installed the application.
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\bin\mysqld-nt.exe"
--defaults-file="C:\\Program Files\\MySQL\\MySQL Server \\my.ini"
--init-file=C:\\mysql-init.txt
After you open the MySQL Server, you can safely delete the .txt file.
On Unix systems, you will need to log in using the Unix account where the server runs and to locate the .pid file that contains the server's process ID. Usually, you can find this file in /var/lib/mysql/, /var/run/mysqld/, and /usr/local/mysql/data/ directories. Once you locate the file, use kill cat /mysql-data-directory/host_name.pid
to stop the MySQL server. Make sure you use "``" backticks before "cat" and after ".pid". Once the server has been stopped, create a text file with the following code:
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;
After that, save the file as mysql-init and start MySQL Server using the following command:
mysqld_safe --init-file=/home/me/mysql-init &
After you open the server, you can safely delete the mysql-init file.