Reset Mysql Root Password Script

January 23rd, 2009

Lost (forgotten) your mysql root / admin password? Not to worry, it happens to the best of us.

This simple BASH password reset script will enable you to reset any mysql user password without knowing the current password

I would not recommend running it on a live production system as it requires shutting down the mysql server.

Heres the script:, it needs to be run as root.

# Kill any mysql processes currently running
echo 'Shutting down any mysql processes...'
killall -vw mysqld
 
# Start mysql without grant tables
mysqld_safe --skip-grant-tables >res 2>&1 &
 
echo 'Resetting password...'
 
#Sleep for 5 while the new mysql process loads (if get a connection error you might need to increase this.
sleep 5
 
#Update user with new password
mysql mysql -e "UPDATE user SET Password=PASSWORD('$2') WHERE User='$1';FLUSH PRIVILEGES;"
 
echo 'Cleaning up..'
 
#Kill the insecure mysql process
killall -v mysqld

First variable is the user you want to reset, second variable is the password.

sh mysqlreset root newpassword
del.icio.us Digg Furl Reddit Ma.gnolia RawSugar Shadows Spurl StumbleUpon Tailrank Technorati

Tags: Linux

RSS feed | Trackback URI

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line=""> in your comment.

Article Categories

Recent Articles

Recommended

Feeds