I have been using DigitalOcean for my personal projects. And one repeated things that I had to do is the creation of MySQL database & user. I know I could have used some CPanel like GUIs and even some of them came to my mind like VestaCP, Ajenti, ServerPilot, etc. But all come with sort of things and not so developer friendly.
So I decided to create a simple bash script that can simplify the database & user.
Bash Script Code
You can find the script at Gist:
How to use?
Download the script from Gist – Bash Script: Create MySQL Database & User
2# Set Permission
You need to set the executable permission in order to execute the shell script:
chmod +x mysql-create-db-user.sh
Use the script as:
./mysql-create-db-user.sh [--host="<host-name>"] --database="<db-name>" [--user="<db-user>"] [--pass="<user-password>"]
So the only required parameter is the database name. In the case of empty values for other parameters:
- ‘host’ becomes localhost
- ‘user’ takes value from database name
- ‘password’ is randomly generated
For the following command:
The output looks like:
Hope you find this script useful.
Please do let us know any feedback in the comments below.