Skip to content
Setting up the database

Setting up a MySQL database in Python with PlanetScale

This course is going to cover how to use MySQL with Python. This is going to be a hands-on course, so you'll need a MySQL database if you want to follow along. We'll be using PlanetScale for the entirety of the course.

Let's get the database set up.

You'll follow these steps to set everything up:

  1. Create a PlanetScale account
  2. Create a new database
  3. Install the PlanetScale CLI
  4. Set up the Python script

Step 1: Create a PlanetScale account

First, visit PlanetScale and create an account.

Step 2: Create a new database

To create a new database, scroll down to the bottom of the dashboard and click on the "Create" link.

Enter a name for your database. In our case, we'll use hotel_management. Click on "Create database" and wait for a moment as PlanetScale creates the database for you.

Step 3: Install the PlanetScale CLI

Next, we need to install the PlanetScale Command Line Interface (CLI). This is essential for interacting with the remote database from our local machine using the terminal. Head to the PlanetScale CLI environment setup doc and look for the installation instructions for your operating system (in our case, we are using Windows).

Step 4: Log in with the PlanetScale CLI

Next, we need to log into our PlanetScale account using the CLI. Run the following command in your terminal:

pscale login

This will open a new window in your browser where you will have to enter a confirmation code. Make sure the code in the browser matches the code in your terminal.

Click "Confirm code" and, after you have successfully logged in, close the tab.

Now, you have successfully set up the PlanetScale CLI and the remote database. In the next section, we will set up the Python script to interact with the remote database.


In this tutorial, we learned how to use a remote MySQL-compatible database with Python, specifically PlanetScale. We can now create databases, and interact with them using the PlanetScale CLI. This provides a powerful way to work with remote databases, enabling you to execute SQL statements from your local machine using Python.

About this lesson

Set up your PlanetScale MySQL database to use in a Python application.

Closed captioned

Meet your instructor, Anthony Herbert

Software Developer

I'm a software developer and educator focused on helping others build their dream software projects.

Feedback or questions? Reach out to our team at

By submitting your email, you agree to the processing of your personal information by PlanetScale as described in the Privacy Policy.