SQL Zone is brought to you in partnership with:

Highly motivated Senior Java/JEE Software Developer with 7+ years of solid industry experience. Excellent team player with an experience working in distributed international teams, using Agile/Scrum methodology. Artur has posted 9 posts at DZone. You can read more from them at their website. View Full User Profile

Reset MySQL Root Password On Linux

05.13.2011
| 5000 views |
  • submit to reddit

 

 Five easy steps to reset MySQL root password.

  1. Stop the MySQL server.
  2. Start the MySQL server with the --skip-grant-tables option. (it will not prompt for password)
  3. Connect to MySQL server as the root user. 
  4. Setup new MySQL root password.
  5. Exit and restart the MySQL server. 

    
### Shell Commands ###
/etc/init.d/mysql stop
mysqld_safe --skip-grant-tables & 
mysql -u root

### SQL Commands ###
use mysql;
UPDATE user SET password=PASSWORD("new-password") WHERE user='root';
flush privileges;
exit

### Shell Commands ###
/etc/init.d/mysql stop
/etc/init.d/mysql start
mysql -u root -pnew-password  
Published at DZone with permission of its author, Artur Mkrtchyan.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)