Advertisement
Guest User

Untitled

a guest
Feb 11th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. clear
  2.  
  3. read -p "Please enter your desired MySQL username: " USER
  4. echo $USER
  5. read -p "Please enter your desired MySQL password: " PASS
  6. echo $PASS
  7. read -p "Please enter your desired ROOT password: " ROOTPASS
  8. echo $ROOTPASS
  9.  
  10. ########################################
  11. ### Secure MySQL Installation Script ###
  12. #######################################
  13. apt-get -y install expect
  14.  
  15. MYSQL_ROOT_PASSWORD=$ROOTPASS
  16.  
  17. SECURE_MYSQL=$(expect -c "
  18. set timeout 10
  19. spawn mysql_secure_installation
  20. expect \"Enter current password for root (enter for none):\"
  21. send \"$MYSQL\r\"
  22. expect \"Change the root password?\"
  23. send \"n\r\"
  24. expect \"Remove anonymous users?\"
  25. send \"y\r\"
  26. expect \"Disallow root login remotely?\"
  27. send \"y\r\"
  28. expect \"Remove test database and access to it?\"
  29. send \"y\r\"
  30. expect \"Reload privilege tables now?\"
  31. send \"y\r\"
  32. expect eof
  33. ")
  34.  
  35. echo "$SECURE_MYSQL"
  36.  
  37. apt-get -y purge expect
  38.  
  39. sleep 1
  40.  
  41.  
  42. ######################
  43. ### MySQL Commands ###
  44. ######################
  45. echo "
  46. CREATE USER '$USER'@'localhost' IDENTIFIED BY '$PASS';
  47. GRANT ALL PRIVILEGES ON *.* TO '$USER'@'localhost' WITH GRANT OPTION;
  48. CREATE USER '$USER'@'%' IDENTIFIED BY '$PASS';
  49. GRANT ALL PRIVILEGES ON *.* TO '$USER'@'%' WITH GRANT OPTION;
  50. FLUSH PRIVILEGES;" >> commands.sql
  51.  
  52. mysql < "commands.sql"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement