1、点击链接,下载PostgreSQL,然后安装(安装时locale选择C),并配置环境变量,在用户变量->path中添加D:\Program\PostgreSQL\13\bin和D:\Program\PostgreSQL\13\pgAdmin 4\bin,在系统变量->path中添加D:\Program\PostgreSQL\13\bin和D:\Program\PostgreSQL\13\pgAdmin 4\bin;
2、在命令行输入pgAdmin4
,进入PostgreSQL客户端,如下图所示,创建Database;
3、python调用PostgreSQL API,首先pip install psycopg2,然后运行如下代码,创建Table;
import psycopg2
conn = psycopg2.connect(database="DRMS", user="postgres", password="123456", host="127.0.0.1", port="5432")
print ("Open database successfully")
cur = conn.cursor()
# 创建Table
cur.execute('''CREATE TABLE if not exists PRODUCT(
PRODUCT_ID CHAR(20) PRIMARY KEY,
PRODUCT_NAME CHAR(40) )''')
print ("create table successfully")
conn.commit()
conn.close()