Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Add Comment
Please, Sign In to add comment