Advertisement
Guest User

Untitled

a guest
May 5th, 2016
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #!/bin/bash
  2. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  3. export PATH
  4.  
  5. # Check if user is root
  6. if [ $(id -u) != "0" ]; then
  7. echo "Error: You must be root to run this script!"
  8. exit 1
  9. fi
  10.  
  11.  
  12. mysql_root_password=""
  13. read -p "Enter New MySQL root password: " mysql_root_password
  14. if [ "${mysql_root_password}" = "" ]; then
  15. echo "Error: Password can't be NULL!!"
  16. exit 1
  17. fi
  18.  
  19. echo "Stoping MySQL..."
  20. /etc/init.d/mysql stop
  21. echo "Starting MySQL with skip grant tables"
  22. /usr/bin/mysqld_safe --skip-grant-tables >/dev/null 2>&1 &
  23. echo "using mysql to flush privileges and reset password"
  24. sleep 5
  25. echo "update user set password = Password('${mysql_root_password}') where User = 'root'"
  26. /usr/bin/mysql -u root mysql << EOF
  27. update user set password = Password('${mysql_root_password}') where User = 'root';
  28. EOF
  29.  
  30. reset_status=`echo $?`
  31. if [ ${reset_status} = "0" ]; then
  32. echo "Password reset succesfully. Now killing mysqld softly"
  33. killall mysqld
  34. sleep 5
  35. echo "Restarting the actual mysql service"
  36. /etc/init.d/mysql start
  37. echo "Password successfully reset to '${mysql_root_password}'"
  38. else
  39. echo "Reset MySQL root password failed!"
  40. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement