Created
July 19, 2012 08:55
-
-
Save wridgers/3141683 to your computer and use it in GitHub Desktop.
A mysql password recovery utility.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# resetRootPass script | |
# | |
# Recover lost root password of mysql database. | |
# | |
# By Willem Bermon | |
# | |
echo | |
echo "Mysql password recovery utility" | |
echo | |
# Stop the mysql server | |
/etc/init.d/mysql stop | |
/etc/init.d/mysql zap > /dev/null | |
/bin/killall mysqld > /dev/null | |
# Run mysqld in permissionless mode | |
/sbin/start-stop-daemon --start --quiet --exec /usr/bin/mysqld_safe \ | |
--background -- --skip-grant-tables >/dev/null 2>&1 | |
sleep 1 | |
# Execute queries | |
mysql -u root mysql -e "UPDATE user SET Password=PASSWORD('$1') WHERE \ | |
user='root'; \ | |
FLUSH PRIVILEGES;" | |
if [[ $? -eq 0 ]] | |
then | |
echo " ** SQL root password updated" | |
else | |
echo " ** SQL root password update unsuccesful" | |
fi | |
# Restart the mysql server | |
/bin/killall mysqld > /dev/null | |
/etc/init.d/mysql start | |
echo "Succesfully updated password!!" | |
echo | |
echo | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment