September 2010
Intermediate to advanced
440 pages
9h 23m
English
The ability to create users is obviously an administrative task. By default, this means that one must log in as root, or any other user who has administrative rights, to use them. If your Python program does not login as root, it will not be able to affect user creation. Therefore, one's connection credentials must read accordingly:
import MySQLdb
mydb = MySQLdb.connect(host = 'localhost',
user = 'root',
passwd = 'rootsecret')
cursor = mydb.cursor()From here, one can similarly form the statement to the other CREATE statements that we have used.
statement = """CREATE USER 'exemplar'@'localhost' IDENTIFIED BY 'MoreSecurity'""" cursor.execute(statement)
In a Python shell, passing the statement through cursor.execute() will ...
Read now
Unlock full access