First time here? Check out the FAQ!
x

Resetting MySQL password.

0 votes
asked by about MySQL Community Server
edited by

I installed MySQL, but I no longer remember my password. Yesterday, I tried to open it but the password was totally wrong. Can you help me to renew my password? I need to use it for my final year project.

2 Answers

0 votes
answered by (3.1k points)

The default password is blank with "su" as username. You can actually find the config file on the hard drive located in the server folders. You can edit the text via NotePad.

0 votes
answered by (132k points)

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.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register
...