Advertisement
Guest User

Untitled

a guest
Feb 16th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. # Please confirm that you want to reset the MySQL passwords
  2. CONFIRM="n"
  3. echo -n "Please confirm MySQL password reset. Continue? (y/N): "
  4. read -n 1 CONFIRM_INPUT
  5. if [ -n "$CONFIRM_INPUT" ]; then
  6. CONFIRM=$CONFIRM_INPUT
  7. fi
  8.  
  9. echo
  10.  
  11. # check if we are resetting the MySQL password
  12. if [[ "${CONFIRM}" =~ ^[Yy]$ ]]; then
  13.  
  14. # Kill any mysql processes currently running
  15. echo 'Shutting down any mysql processes...'
  16. service mysql stop
  17. killall -vw mysqld
  18.  
  19. # Start mysql without grant tables
  20. mysqld_safe --skip-grant-tables >res 2>&1 &
  21.  
  22. echo 'Resetting password... hold on'
  23.  
  24. # Sleep for 5 while the new mysql process loads (if get a connection error you might need to increase this.)
  25. sleep 5
  26.  
  27. # Creating the password
  28. DB_ROOT_PASS_LEN=`shuf -i 20-30 -n 1`
  29. DB_ROOT_PASS=`pwgen -scn $DB_ROOT_PASS_LEN 1`
  30. DB_ROOT_USER='root'
  31.  
  32. # Update root user with new password
  33. mysql mysql -e "UPDATE user SET Password=PASSWORD('$DB_ROOT_PASS') WHERE User='$DB_ROOT_USER';FLUSH PRIVILEGES;"
  34.  
  35. echo 'Cleaning up...'
  36.  
  37. # Kill the insecure mysql process
  38. killall -v mysqld
  39.  
  40. # Starting mysql again
  41. service mysql restart
  42.  
  43. echo
  44. echo "Password reset has been completed"
  45. echo
  46. echo "MySQL root password: $DB_ROOT_PASS"
  47. echo
  48. echo "Remember to store this password safely!"
  49. else
  50. echo "Password reset was aborted"
  51. fi
  52.  
  53. echo
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement