How to reset MySQL password

Q I have a Mandrake system, which I set up with security at the top of my priority list. I chose good strong passwords, disabled a load of services that weren't required, do regular updates and even got an excellent iptables setup off Google to use as a template. I'm now secure, very secure - too secure! I failed to write down the MySQL password, because that's bad security practice right? And now I can't remember what it is. My organisation is trying to get a database added for our first web application and I can't do it. Is there a way to reset the MySQL password to a default or reinstall MySQL without risking my existing data going to the bit bucket?

A Fortunately MySQL has thought of just this type of situation! The following should fix you up:

etc/rc.d/init.d/mysql stop
/usr/bin/safe_mysqld --skip-granttables &
mysql -u root

The password is actually kept in an encrypted form in the MySQL database. You'll find yourself at a MySQL prompt - all you need to do is update the password and you're set.

UPDATE user SET
Password=PASSWORD("your new
password here")
WHERE User="root";
exit

Once you're back at the Linux prompt you'll need to bring the backgrounded safe_mysqld to a stop, which is probably easiest by typing fg 1 and hitting Ctrl+C. The last thing left to do is bring the MySQL service back up with /etc/init.d/mysqld start and give it a test.

Follow us on Identi.ca or Twitter

Username:   Password:
Create Account | About TuxRadar