Member-only story

How to Use Python with a Database

Eric Chi
11 min readJun 13, 2023

Photo by valentinadragun on Wallpapers.com

Complete source code can be found here: https://github.com/ericjaychi/sample-python-database-connection

One of the most important pieces of any modern-day application is a database. I don’t think anyone will argue that. So this is a kickstart guide on some of the basics when it comes to working with one of the most important pieces of technology in any program.

Table of Contents

  • Step 1: Installing a Database
  • Step 2: Database Concepts
  • Step 3: Installing Python’s MySQL Connector
  • Step 4: Creating a Database
  • Step 5: Creating a Table
  • Step 6: Creating a Row
  • Step 7: Reading Rows
  • Step 8: Updating a Row
  • Step 9: Deleting a Row

Step 1: Installing a Database

Depending on the database, the installation will differ. Luckily the database of choice within this blog, MySQL, has installers for the most popular operating systems.

First go to: https://downloads.mysql.com/archives/community/

Go through the options to pick a version of MySQL that best fits your operating system, the operating system version, and the specific chip you have. For those that are on the new Apple Silicon chips, the ARM selection is the one you want.

If you can’t find the installer, be sure to move the MySQL version number around, as specific versions of MySQL support specific operating system versions.

Quick overview of the installer on macOS.

After the installer has finished running, MySQL should be installed on your machine now!

Before we continue, it would be a good idea to quickly verify if you have MySQL installed on your machine.

macOS

  • Open the Terminal.
  • Run mysql -u root -pinside of the terminal.
  • Enter your password that was set during the installation phase. If there was non asked, usually the default is root or a…

Eric Chi
Eric Chi

Written by Eric Chi

Passion for learning, teaching, and helping others understand the world of software. Currently working @ Apple

No responses yet

Write a response