SHARE
TWEET

Untitled

a guest Sep 11th, 2019 177 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. execute_query()
  4. {
  5.   echo "Executing $1"
  6.   sudo mysql --execute="$1"
  7. }
  8.  
  9. password=$(< /dev/urandom tr -dc A-Z-a-z-0-9 | head -c${1:-64};)
  10. password="${password}."
  11.  
  12. echo
  13.  
  14. read -r -p 'Database: ' database
  15. read -r -p 'Username: ' username
  16. echo "Password: $password"
  17.  
  18. echo
  19.  
  20. execute_query "CREATE USER '$username'@'localhost' IDENTIFIED BY '$password';"
  21. execute_query "GRANT select,update,insert,delete ON $database.* TO '$username'@'localhost';"
  22. execute_query "FLUSH PRIVILEGES;"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top