Last active
November 16, 2017 07:15
-
-
Save ashutoshsmaurya/eff483107d600d1d7e6bc5683239f0ec to your computer and use it in GitHub Desktop.
Reset MySLQ User Password
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 | |
#Confirm that you want to reset the MySQL passwords | |
CONFIRM="n" | |
echo -n "Please confirm MySQL password reset for continue? (y/N): " | |
read -n 1 CONFIRM_INPUT | |
if [ -n "$CONFIRM_INPUT" ]; then | |
CONFIRM=$CONFIRM_INPUT | |
fi | |
echo | |
#Check if we are resetting the MySQL password | |
if [[ "${CONFIRM}" =~ ^[Yy]$ ]]; then | |
#Stop any mysql processes currently running | |
systemctl stop mariadb >&/dev/null; service mysqld stop >&/dev/null; systemctl stop mysql >&/dev/null; service mysql stop >&/dev/null | |
killall -vw mysqld >&/dev/null | |
#Now Start mysql without grant tables | |
mysqld_safe --skip-grant-tables >res 2>&1 & | |
#Read User Name & Password | |
read -p "Enter The Database User Name : " DB_ROOT_USER | |
read -s -p "Enter The User-$DB_ROOT_USER, New Password (Note- One Time Press Enter Key & Wait): " DB_ROOT_PASS | |
#Update user with new password | |
mysql mysql -e "UPDATE user SET Password=PASSWORD('$DB_ROOT_PASS') WHERE User='$DB_ROOT_USER';FLUSH PRIVILEGES;" | |
killall -vw mysqld >&/dev/null | |
#Sleep few seconds.. while the new mysql process loads. | |
clear | |
echo "#################################################################################################" | |
systemctl restart mariadb >&/dev/null; service mysqld restart >&/dev/null; systemctl restart mysql >&/dev/null; service mysql restart >&/dev/null | |
LOAD="Resetting Password Hold On Few Seconds...... MySQL User- $DB_ROOT_USER, Password: $DB_ROOT_PASS Wait.....&Done!!" | |
for i in {1..200}; do | |
echo -ne "\r${LOAD:0:$i}" | |
sleep .10 | |
done | |
else | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment