The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
FreeBSD Support
 New Topic  |  Go to Top  |  Go to Topic  |  Search  |  Log In   Newer Topic  |  Older Topic 
 HowTo: change root mysql password if you lose it
Author: Stephen VanDyke 
Date:   18-10-00 19:48

I had to do this a while ago and thougt it would make a nice howto on the site :)

Stephen VanDyke


Here's a complete howto on what to do if the root password is ever lost/changed and it has to be changed back.

You must be either the Unix root user or the same user the server runs as to do this.

Take down the mysqld server by sending a kill (not kill -9) to the mysqld server.
The pid is stored in a .pid file which is normally in the MySQL database directory:

kill `cat /mysql-data-directory/`

Restart mysqld with the --skip-grant-tables option

/path/to/mysqld --skip-grant-tables

Connect to the mysqld server with mysql -u root

MySQL should drop you straight to the sql command line without prompting for a password

connect to the mysql database with "connect mysql"

Update priveledges on the user you need to regain access to, you may need
to perform a "select * from user" to confirm what accounts they have set-up

"UPDATE user SET password=PASSWORD('newpassword') WHERE user='root';

Flush the priveledges cache that was NOT initially loaded


Log out of MySQL, and attempt to relog in.
mysql -u root -p password newpassword

10. If everything works, kill the current running mysql daemon and restart as you would normally.

Reply To This Message
 RE: HowTo: change root mysql password if you lose
Author: Dan Langille 
Date:   18-10-00 21:12

Thanks! I remember needing to do that once. I can't remember how I got around it.

Reply To This Message
 Forum List  |  Threaded View   Newer Topic  |  Older Topic 

 User Login
 User Name:
 Remember my login:
 Forgot Your Password?
Enter your email address or user name below and a new password will be sent to the email address associated with your profile.
How to get the most out of the forum