连接服务

最近更新时间: 2024-10-17 17:10:00

#coding=utf-8
#!/usr/bin/python
import psycopg2
try:
    conn = psycopg2.connect(database="postgres", user="tbase", password="", host="172.16.0.29", port="15432")
    print "连接数据库成功"
    conn.close()
except psycopg2.Error,msg:
    print "连接数据库出错,错误详细信息: %s" %(msg.args[0])

运行

[tbase@VM_0_29_centos python]$ python conn.py 
#连接数据库成功