Welcome to our Python database course!
PlanetScale’s free Python MySQL course guides you through setting up a database, installing MySQL (and building a Flask app), using cursors, creating a table, and so much more.
Follow along with your instructor as they guide you through our original Python Flask course, and be sure to reach out to us with feedback or questions.
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:
- Create a PlanetScale account
- Create a new database
- Install the PlanetScale CLI
- Set up the Python script
First, visit PlanetScale and create an account.
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.
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).
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.