HomePython Database Programming in Python: Accessing MySQL
Database Programming in Python: Accessing MySQL
While data storage for applications is no longer considered complex, it is now simplified to the point that flexibility is sacrificed. There is a good compromise, however. In this article, you will learn how to access a a MySQL database with Python.
Data forms the base of all application programs. Whatever the domain, the core of the application's logic goes into extraction, processing, storage and presentation of the data. Each of these has evolved into a specialized domain of its own.
If storage is the context, then anything from persisting data to a file to persisting it into a database can become a part of the core logic. In the early days of programming, any level of storage of data was considered complicated, especially in databases. However in this era of Very High Level Programming Languages, complexity has become a thing of past (almost).
The major issue with VHLL is that most of them sacrifice flexibility for simplicity. Equilibrium between flexibility and simplicity must exist so that data-bound applications need not be termed either complex or user-unfriendly. This is where languages such as Python play a pivotal role.
The beauty of Python is that it can provide abstraction in data access and processing at various levels. In other words, Python provides for database access both at the SQL level as well as at the object level and to almost any database.
That justifies the first part of this article's title. Coming to the second part, of all the relational databases, MySQL is the best bet. There are two reasons. The first one is that MySQL is free. The second one is that MySQL is comparatively less resource hungry. Hence, a Python-MySQL combination is a good option for a data-bound application.
The first sections of this article will deal with the steps required for connecting with and retrieving data from MySQL. In the last section I will put the theory into practice by applying it in a real-world example. Thatís the agenda for this discussion.