Connect MySQL DB using python

Viraj Wadate
1 min readApr 23, 2019

Connect MySQL db using python script. Use config.ini file for configurations.

We are going to see how to retrieve all records from MySQL table using python script.

Prerequisite:
1] Python [2.7 or 3.X] : [https://www.python.org/downloads/]
2] MySQL install on your system :
windows user [https://www.mysql.com/downloads/]
Ubuntu user [sudo apt-get install mysql-server]
3] pip install mysql-connector

Let’s write program: We required two files to connect MySQL and retrieve data
1] connect_mysqldb.py : Containing the python code
2] config.ini : MySQL DB configurations like hostname, username, password, port, etc.

connect_mysql.py
config.ini

Conclusion :
Thanks for reading this article. I hope it is useful for you guys. Still there are many ways remain to connect and retrieve data from database. If you are facing any issue please let me know.

--

--

Viraj Wadate

Hi Everyone, I am a software developer from Pune. I am a passionate programmer also I post video related programming on my YouTube channel VirajWadate