In this section, we will introduce how to use database as backend storage. We will use MySQL as an example.
- MySQL 5.7 or higher
- Python 3.6 or higher
- Python MySQL Connector
First, we need to create a database for our project. We can use MySQL command line tool to create a database named mydb
:
CREATE DATABASE mydb;
Then, we need to create a table named mytable
in the database. We can use MySQL command line tool to create a table named mytable
:
CREATE TABLE mytable (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
PRIMARY KEY (id)
);
Next, we need to create a user for our project. We can use MySQL command line tool to create a user named myuser
:
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
Finally, we need to grant privileges to the user. We can use MySQL command line tool to grant privileges to the user: