Change and Reset MySQL root Password
Other then the ways specified here to reset and change the root password for mySQL database in the case that the password is forgotten or lost, the following instructions explain in details the alternative way at the last part of the guide, where no additional file needs to be created:
- Login as root to the Windows or Unix-like (Unix, Linux or BSD) machine with the MySQL server.
- Stop the MySQL server by using either of the following command:
Linux: /etc/rc.d/init.d/mysql stop
FreeBSD: /usr/local/etc/rc.d/mysql-server.sh stop - Open the mysql server startup script (i.e. mysql-server.sh - the file executed to start or stop MySQL server.
- Add –skip-grant-tables to the end of the line that contains the mysqld_safe command as its parameter.
- Start MySQL server with the following command:
Linux: /etc/rc.d/init.d/mysql start
FreeBSD: /usr/local/etc/rc.d/mysql-server.sh start - Alternatively, start the MySQL server directly and skip the editing with the following command:
mysqld_safe –skip-grant-tables &
Depending on your path environment, you may need to point to the correct directory where mysqld_safe is instead.
- Run the following commands to login as the mysql user and connect to mysql user/permission database:
# mysql -u root mysql
- Run the update queries to change the MySQL password:
mysql> UPDATE user SET Password=PASSWORD(’newrootpassword’) WHERE User=’root’;
mysql> FLUSH PRIVILEGES;Note: Replace newrootpassword with the new root password for MySQL server. Flush Privileges is needed to making the password change effect immediately.
- Exit mysql database client by typing exit.
- Stop MySQL server with commands listed at step 2.
- Open the mysql server startup script edit in step 3 again and remove the –skip-grant-tables parameter that has been added.
- Start MySQL server by using command from step 5 or 6.
For Redhat Linux users, use the following instructions as the root user of Redhat Linux machine:
- Stop MySQL process by using command:
# killall mysqld
- Start the MySQL server with following options:
# /usr/libexec/mysqld -Sg –user=root &
- Start the MySQL client:
# mysql
You should see the following message:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1 to server version: 3.xx.xxType ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.
mysql>
- Use mysql database:
mysql> USE mysql
You should see the following message:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
- Then, update the password for the root user with the following command:
UPDATE user SET password=password(”newpassword”) WHERE user=”root”;
Replace newpassword with your desired password. You should see the following message:
Query OK, 2 rows affected (0.03 sec)
Rows matched: 2 Changed: 2 Warnings: 0Rows affected may be different, but the Query OK should be there.
- Flush the database privileges to reload it in order to make the changes effective:
mysql> flush privileges;
You should get the following result:
Query OK, 0 rows affected (0.02 sec)
- Exit the MySQL client by typing exit.
- Kill the MySQL server process by typing killall mysqld.
- Then start MySQL again:
/etc/init.d/mysqld start
Share and contribute or get technical support and help at My Digital Life Forums.
Related Articles
- Installing Web Server in FreeBSD 6.0 with Apache 2.2, MySQL 5.0 and PHP 5 - Part 3
- Reset the Root Password of MySQL Server
- Install Web Server in Windows XP with Apache2, PHP5 and MySQL4 - Part 4
- Check and Optimize MySQL Database Automatically with Crontab/Cron
- How to Recover and Reset Gmail (Google Account) Password
- How to Reset AdSense Password Not Associated with Google Account
- How to Reset WordPress Password to Recover Forgotten Secret
- Change Oracle Database User Password
- Apple iPhone Root Password and Mobile User Password
- Fix for Munin MySQL Monitoring Plugin Graph Not Showing or Blank

































June 6th, 2006 18:18
[...] Alternatively, on any platform, mysql client can be used to set the new password, althought it’s less secure way of resetting the password (detailed instruction here): [...]
July 9th, 2006 12:05
I wanna reset my ZXDSL 831 ADSL Modemn
Plz tell me the way how to reset it
I need to do that right now
Best Rgds
dugger(vincitore)
December 19th, 2006 14:54
[...] Re: Help me retrieve my password Try this link… Change and Reset MySQL root Password
April 23rd, 2007 08:23
[...] Change and Reset MySQL root Password » My Digital Life (tags: mysql administration) No Tags Gelesen: 2 / heute: 2 [...]
May 5th, 2008 16:52
[...] judulnya), setelah googling cuma dapat cara untuk mereset dan mengganti password MySQL di UNIX-like di sini. Wah, perlu sedikit modifikasi ni … Berikut cara2 yang saya lakukan: 1. Kill proses MySQL [...]
July 3rd, 2008 05:46
On ubuntu, command is mysqld_safe –-skip-grant-tables &
Extra dash is required so mysql can parse it correctly.