Link to home
Start Free TrialLog in
Avatar of Jerry L
Jerry LFlag for United States of America

asked on

Bash Shell Script to Create mySQL Database

I'm using a domain hosting server that runs Red Hat Linux.

BACKGROUND:
I'm attempting to automate the creation of new addon domains that require a mySQL database and user with password.

QUESTION:
Can you help me write a bash shell script that will ...
1) Create a database; the name of the database needs to be generated using the domain name as a seed word, but it must have minimal encoding as well. Something like this:  mydomain > MydOM@1n
2) Create a user with password and permissions, and assign it to that database. I will need some sort of random password generator also, that will provide passwords for the user.
3) If you think Perl has better resources for this, please let me know.

Avatar of Codebot
Codebot

db="create database xxx;GRANT ALL PRIVILEGES ON xxx.* TO user@localhost IDENTIFIED BY 'password';FLUSH PRIVILEGES;"
mysql -u root -p$mysql_pass -e "$db
Avatar of Jerry L

ASKER

1) Thank you for your attempt, but please write the code so that is is ready to run as-is. Codebot, above, appears to be pseudo-code, and does not fulfill the request as specified in my original question.

2) Something I will add, it has been suggested that granting fewer privileges to the db user is more secure. Therefore, I will need to know the code to select only these:

Select
Insert
Update
Delete
Create
Alter
ASKER CERTIFIED SOLUTION
Avatar of Vryali
Vryali
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial