First, install the third-party library
To connect to the mysql database, you need to use the third-party library PyMySQl
pip install PyMySQl
Second, common database operations
Establish a database connection: MySQlconnect = pymysql.connect("database address", "database port", "database account", etc.)
Get the operation cursor: cursor = MySQlconnect .cursor()
Execute SQL statement: cursor.execute("SQL statement")
Get a piece of data: data = cursor.fetchone()
Get results (read): cursor.fetchall()
Commit changes (write): MySQlconnect .commit()
Close the cursor: cursor.close()
Close the connection: MySQlconnect.close()