Python Mysql connection and extracting sample data

In this tutorial we are going to learn how to connect to MYSQL using python.

DB Configuration:

First of all we need a that will act as a configuration file that our python script will read. This configuration file consists information of MYSQL database username and password, database name and host where the MYSQL is at.

This is how will look like

server = dict(
    #serverip = 'localhost',
    dbhost = 'localhost',
    dbname = 'userdb',
    dbuser = 'root',
    dbpassword = 'root123'

Then the actual python script that will connect using these parameters to our db and fetch results as needed.