Page 26 - Phyton_GUIprogrammingwithTkinter
P. 26

P a ge  | 17


               3.3  MySQL

                         MySQL is one of the most popular database management systems (DBMSs) on the
                    market today. As most software applications need to interact with data in some form,
                    programming languages like Python provide tools for storing and accessing these data
                    sources.

                         To  connect Python  with  the MySQL  database  we need  to install the MySQL
                    connector.  MySQL Connector enables Python programs to access MySQL databases,
                    using an API that is compliant with the Python Database API Specification v2.0 (PEP 249).
                    It is written in pure Python and does not have any dependencies except for the Python
                    Standard Library.


               3.3.1  MySQL Installation


                         MySQL  should be  installed on our computer  before we connect a  database to
                    Python file. MySQL is a server-based database management system. One server might
                    contain multiple  databases. To interact with a database,  we  must first establish a
                    connection with the server. The general workflow of a Python program that interacts
                    with a MySQL database is as follows:
                         a)  Connect Python file to the MySQL server.
                         b)  Create a new database.
                         c)  Connect to the newly created or an existing database.
                         d)  Execute a SQL query and fetch results.
                         e)  Inform the database if any changes are made to a table.
                         f)  Close the connection to the MySQL server.

                    This is the most basic work process depending on the application being developed.

                    However, no matter what application is generated, the first step is to make a database

                    connection to our application.


               3.3.2   Step to Install MySQL Connector in Python


                   1.  Install MySQL Workbench to create a database on our localhost. Download a free
                       MySQL database at http://dev.mysql.com/downloads/workbench/.
   21   22   23   24   25   26   27   28   29   30   31