Take the 2-minute tour ×
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.

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 ?

Thanks!

share|improve this question
1  
"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
add comment

4 Answers

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 newuser.sh

#!/bin/bash

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

Then do

$ ./newuser.sh gaius abc123
share|improve this answer
add comment

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

share|improve this answer
add comment

Creating a view is nothing more than

create db.view as select ...

What do you want to automate here?

share|improve this answer
add comment

Stored procedures

Perl

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
add comment

Your Answer

 
discard

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.