Test Code/Linux

[Ubuntu] Python PostgreSql 접속하기

yaks101 2015. 3. 30. 16:31


1. 먼저 psycopg2 설치 합니다.


> apt-get install python-psycopg2



2. python 구문 작성


#! /usr/bin/python2.7

import psycopg2

try:
	conn = psycopg2.connect("dbname='test' user='test' host='localhost' password='1'")
	print "connect ok"

except: print "error"



3. 실행

> python test.py