import pymysql
conn = pymysql.connect(host='127.0.0.1',
user='root',
password='123456',
port=3306)
cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)
affect_rows = cursor.execute('create database blog;')
print(affect_rows) # 输出 1
cursor.close()
conn.close()
运行后,可以在 MySQL 中看到 blog 库。