Skip to content

Instantly share code, notes, and snippets.

@miaoles
Last active May 7, 2021 20:07
Show Gist options
  • Save miaoles/c802610df2aa357b782148741d210aca to your computer and use it in GitHub Desktop.
Save miaoles/c802610df2aa357b782148741d210aca to your computer and use it in GitHub Desktop.
#!/bin/bash
PASSWORD='pa$$w0rd'
for name in $(cat users.txt); do
sudo mysql> CREATE DATABASE '$name'
sudo mysql> CREATE USER '$name'@'localhost' identified by '${PASSWORD}';
sudo mysql> GRANT ALL PRIVILEGES ON ${name}.* TO '$name'@'localhost' IDENTIFIED BY '${PASSWORD}'
echo "User $name created with password $PASSWORD with database $name"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment