Python's mysql database to create tables

a code

import pymysql
# Open database connection
db = pymysql.connect("localhost","root","root","db_test01" )
# Use the cursor() method to create a cursor object cursor
cursor = db.cursor()
# Use the execute() method to execute SQL, and delete the table if it exists
cursor.execute("DROP TABLE IF EXISTS EMPLOYEE")
# create table using prepared statement
sql = """CREATE TABLE EMPLOYEE (
         FIRST_NAME  CHAR(20) NOT NULL,
         LAST_NAME  CHAR(20),
         AGE INT,  
         SEX CHAR(1),
         INCOME FLOAT )"""
cursor.execute(sql)
print("CREATE TABLE OK")
# close the database connection
db.close()

 

Second run results
CREATE TABLE OK

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327090669&siteId=291194637