#!/usr/bin/env python # # Simple utility to generate many mysql GRANT statements to grant # permissions for users to gain access to corralate with a DB created. # # This file will generate the following statements: # GRANT ALL ON User_01_db.* TO 'User_01'@'localhost' IDENTIFIED BY 'User_01'; # to # GRANT ALL ON User_49_db.* TO 'User_49'@'localhost' IDENTIFIED BY 'User_49'; # # Usage: run this file after renaming it to *.py then look out for a SQL file # call createDBUser.sql. One can replace 'localhost' with '%' # # python v2.x.x compatible, not sure with python v3.x.x ########################################################################## import sys import os def main(): a = 1 max1 = 10 users = "User_" mess1 = "GRANT ALL ON " mess2 = "\'localhost\' IDENTIFIED BY " file = "createDBUser.sql" f = open(file,'w') ###################################################################### # Change this number to reflect on the maximum amount of users you # desire. max2 = 50 ##################################################################### while a < max1: tmp = mess1 + users + '0' + str(a) + '_db.* TO ' + "'" + users + '0' + str(a) + "'" + '@' + mess2 + "\'" + users + '0' + str(a) + "\';" f.write(tmp) f.write("\n") a=a+1 while a < max2: tmp = mess1 + users + str(a) + '_db.* TO ' + "'" + users + str(a) + "'" + '@' + mess2 + "\'" + users + str(a) + "\';" f.write(tmp) f.write("\n") a=a+1 f.close() main()