导入pymysql库
import pymysql
创建data数据库
db = pymysql.connect(host = '127.0.0.1', user = 'root', password = 'qqqqqq', port = 3306)
cursor = db.cursor()
cursor.execute('create database data default character set utf8mb4')
db.close()
创建data数据表
db = pymysql.connect(host = '127.0.0.1', user = 'root', password = 'qqqqqq', port = 3306, db = 'data')
cursor = db.cursor()
cursor.execute('create table data(name varchar(4), age int(3) not null, school varchar(10) not null, primary key (name))')
db.close()
网友评论