Database Reference
In-Depth Information
ults ofa fetchall() , which we store in a variable we've named grants . If a row
from grants contains the word USAGE , we skip displaying that. We then parse out the
database and table name, store them in variables named db and tb , and display them. The
last pair of lines extracts the list of privileges and displays them.
Some of the results of running this Python program on my system follow:
User Account: lena_stankoska@localhost
------------------------------------------
database: `rookery`; table: all
privileges: SELECT, INSERT, UPDATE, DELETE
database: `birdwatchers`; table: all
privileges: SELECT, INSERT, UPDATE
User Account: public_api@localhost
------------------------------------------
database: `birdwatchers`; table: all
privileges: SELECT
database: `rookery`; table: all
privileges: SELECT
This is a nice way for the administrator to get a list of users and see what privileges they
have for particular databases and tables, especially because there isn't a built-in function
to dowhat we want.
More Information
If you would likemore information on MySQL Connector/Python, there's an extensive
manual on MySQL's site, including a MySQL Connector/Python Developer Guide . You
might also like to read Mark Lutz'sbook, Learning Python (O'Reilly).
Search WWH ::




Custom Search