
As Python 3 comes pre-installed on most recent Ubuntu distributions, you can dive right in without the hassle of setting it up—though you’ll still need to install the MySQL database yourself.
Before I became a Java developer, Python played a surprisingly important role in my journey. Back then, I spent weekends rebuilding my Excel VBA scripts using Python libraries like Openpyxl, which opened my eyes to its power in automating and analyzing data.
That hands-on experience even helped me land a job during an interview, thanks to Python’s growing relevance in both scripting and data science. Its rich ecosystem of libraries, strong math support, and creative flexibility still make it one of my favorite tools.
In this new series, we’ll explore how to connect Python to a MySQL database and run basic queries—hands-on and beginner-friendly. Let’s jump in and have some fun with code!
Install MySQL connector:
First things first, you need to install the MySQL Connector (I assume you already installed the database on your machine). By the way, as I mention the last time, my environment is Ubuntu Server 20.04 which is installed on my home server.
pip install mysql-connector-python

Basic connector program:
Here, this is our first Python program that connects the language with the MySQL database.
mysql_connection.py

Executed result:

Show-database program:
This is a program that executes the “show database” command on the MySQL server.
mysql_show_db.p

Executed result:

Show-tables program:
This is a program that executes the “show tables” command on the MySQL server.
mysql_show_tbls.py

Executed result:

Select-everything program:
Finally, this is a program that executes the “select * from table_name” command on the MySQL server.
mysql_select.py

Executed result:

Afterthoughts:
So, how was it? Did you like it? If you’re interested, you can do more with you and your own research. Keep learning, keep coding, and keep smiling!
Great new layout
Thanks, my friend!