Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have several core db tables on our system and allow our employees access to these tables via views that just show them the data they need to see.

We created these views in a new db specific to the new user. Creating all of these views requires running several mysql queries.

I would like to automate this process into a script, but feel there must be tools already out there that take a list of queries and run them.

Can anyone recommend any such tools or even any built-in features in mysql that could assist me here ?


share|improve this question
"there must be tools already out there that take a list of queries and run them" You mean.. Like a script? – Benoit Mar 22 '11 at 14:35

Create a text file containing all your commands. Call it newuser.sql. Then when you want to set up a new user, let's call him gaius, you would simply do

$ cat newuser.sql|mysql --user=gaius --password=abc123 somedb

Obviously you could even create new users in a script, let's call it


echo "create user '$1'@'%' identified by password('$2');"|mysql --user=root --password=secret
cat newuser.sql|mysql --user=$1 --password=$2 somedb

Then do

$ ./ gaius abc123
share|improve this answer

Try cron jobs, also known as crontab, cron etc etc.

share|improve this answer

Creating a view is nothing more than

create db.view as select ...

What do you want to automate here?

share|improve this answer

Stored procedures


PHP (especially handy from web page)

GRANT access to each user down at the column level. (As an alternative to VIEWs.)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.