Guest User

Untitled

a guest
Nov 26th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # resetRootPass script
  4. #
  5. # Recover lost root password of mysql database.
  6. #
  7. # By Willem Bermon
  8. #
  9.  
  10. echo
  11. echo "Mysql password recovery utility"
  12. echo
  13.  
  14. # Stop the mysql server
  15. /etc/init.d/mysql stop
  16. /etc/init.d/mysql zap > /dev/null
  17. /bin/killall mysqld > /dev/null
  18.  
  19. # Run mysqld in permissionless mode
  20. /sbin/start-stop-daemon --start --quiet --exec /usr/bin/mysqld_safe \
  21. --background -- --skip-grant-tables >/dev/null 2>&1
  22.  
  23. sleep 1
  24.  
  25. # Execute queries
  26. mysql -u root mysql -e "UPDATE user SET Password=PASSWORD('$1') WHERE \
  27. user='root'; \
  28. FLUSH PRIVILEGES;"
  29. if [[ $? -eq 0 ]]
  30. then
  31. echo " ** SQL root password updated"
  32. else
  33. echo " ** SQL root password update unsuccesful"
  34. fi
  35.  
  36. # Restart the mysql server
  37. /bin/killall mysqld > /dev/null
  38. /etc/init.d/mysql start
  39.  
  40. echo "Succesfully updated password!!"
  41. echo
  42. echo
  43. exit 0
Add Comment
Please, Sign In to add comment