DROPping users in Python

Dropping a user in Python is as easy as passing the MySQL statement through Cursor.execute(). So the syntax is:

DROP USER exemplar@localhost;

This previous syntax can be changed to:

mydb = MySQLdb.connect(host = 'localhost', 
				user = 'root', 
				passwd = 'rootsecret')
cursor = mydb.cursor()
statement = """DROP USER exemplar@localhost"""
cursor.execute(statement)

However, any part of the statement can be dynamically created through the use of string formatting conventions.

Get MySQL for Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.