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

How can I write a script to automate MySQL database grants in a very easy way?

I have a config file that contains the grant changes I want to make. I want the script to read the config file, and make any necessary changes to the access rights as specified in the config file. Essentially, I want the target rights to match the rights in the config file.

share|improve this question
I'm sorry, but what is your question? You want to write a script (so you need to choose a language: perl,python,etc). Then you code the logic you want around the SHOW GRANTS, GRANT, and REVOKE sql commands through the mysql command line. – Derek Downey Jul 26 '12 at 13:43

How about a script that runs SHOW GRANTS, parses the results, and compares it to what it parsed from your config file. Given that info, you can GRANT or REVOKE until the two lists match.

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.