Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (29 sloc) 1.06 KB
# -*- coding: utf-8 -*-
Adds a sequential number of users into a test database
with username: newusern and password newusern
Not for production usage
import MySQLdb
hostname = # FILL IN
username = # FILL IN
password = # FILL IN
# Simple routine to run a query on a database and print the results:
def doQuery( conn, n_users ) :
cur = conn.cursor()
for i in range(0,n_users):
cur.execute("""CREATE USER \'newuser%i\'@\'localhost\' IDENTIFIED BY \'password%i\'""" % (i,i) )
cur.execute( """GRANT ALL PRIVILEGES ON * . * TO \'newuser%i\'@\'localhost\'""" % i )
cur.execute( """FLUSH PRIVILEGES""" )
except MySQLdb.Error, e:
print ("MySQL Error [%d]: %s" % (e.args[0], e.args[1]))
except IndexError:
print ("MySQL Error: %s" % str(e))
if __name__ == '__main__':
print("Using mysql.connector…")
myConnection = MySQLdb.connect( host=hostname, user=username, passwd=password, 20)
doQuery( myConnection )