Chapter 13. Showing MySQL Metadata
In previous chapters, we have moved from the basics of selecting, inserting, creating, and dropping in MySQL through Python. In this chapter, we will look at accessing MySQL's metadata through Python. We have seen a lot of this incidentally in preceding chapters. However, in this chapter, we will look at them in greater depth. By the end of this chapter, we will see the following:
What MySQL metadata is available to us and how to access it
How to get a list of databases and tables
Ways to switch databases on-the-fly
How to get columnar information
This information is very useful for creating intermediate levels of database management. At the end of the chapter, we will look at how to create a class representation of a database.
Within a MySQL session, the easiest way to access metadata is by using the INFORMATION_SCHEMA
pseudo-table. By switching to it with:
USE INFORMATION_SCHEMA;
you can access a plethora of information. Doing this from within a Python program...