Advertisement
Guest User

Untitled

a guest
Sep 11th, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  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;"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement