Last active
January 20, 2019 15:13
-
-
Save azeemhassni/da44f4b026485e56ccaafe6624b2fe9d to your computer and use it in GitHub Desktop.
Add user to mysql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FILENAME='./mysql_add_user.tmp.sql' | |
touch FILENAME; | |
echo "CREATE USER '$1'@'localhost' IDENTIFIED BY '$2';" >> FILENAME; | |
echo "GRANT ALL PRIVILEGES ON * . * TO '$1'@'localhost';" >> FILENAME; | |
echo "FLUSH PRIVILEGES;" >> FILENAME; | |
echo " 🔊 Adding $1 to mysql users"; | |
sudo mysql -u root -p < FILENAME; | |
rm FILENAME; | |
echo " ✅ Added $1 to mysql users"; | |
# For MySQL >= 8.0 | |
FILENAME='$HOME/mysql_add_user.tmp.sql' | |
touch FILENAME; | |
echo "CREATE USER '$1'@'localhost' IDENTIFIED WITH mysql_native_password BY '$2';" >> FILENAME; | |
echo "GRANT ALL PRIVILEGES ON * . * TO '$1'@'localhost';" >> FILENAME; | |
echo "FLUSH PRIVILEGES;" >> FILENAME; | |
echo " 🔊 Adding $1 to mysql users"; | |
sudo mysql -u root < FILENAME; | |
rm FILENAME; | |
echo " Added $1 to mysql users"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
To use this gist follow the following steps.
chmod +x mysql_add_user.sh
command./mysql_add_user.sh username_to_add password_for_the_user
for example if john wants add him as mysql user, He'll execute