23 lines
565 B
Python
23 lines
565 B
Python
import pymysql
|
|
db=pymysql.connect (host='172.16.1.166',user='root',passwd='114514',database='TESTDB',)
|
|
cursor=db.cursor()
|
|
cursor.execute('SHOW TABLES')
|
|
print(cursor.fetchall())
|
|
# 删表
|
|
cursor.execute('DROP TABLE IF EXISTS EMPLOYEE')
|
|
cursor.execute('SHOW TABLES')
|
|
print(cursor.fetchall())
|
|
# 建表
|
|
cursor.execute("""
|
|
CREATE TABLE IF NOT EXISTS EMPLOYEE (
|
|
FIRST_NAME CHAR(20) NOT NULL,
|
|
LAST_NAME CHAR(20),
|
|
AGE INT,
|
|
SEX CHAR(1),
|
|
INCOME FLOAT
|
|
);
|
|
""")
|
|
cursor.execute('SHOW TABLES')
|
|
print(cursor.fetchall())
|
|
cursor.close()
|
|
db.close() |