0
我无法使用psycopg2在Linux中连接到数据库。我已经安装在Linux PostgreSQL和我的代码是:连接数据库时出现错误
import psycopg2
def testEgg():
conn = psycopg2.connect("dbname = myDatabase user = postgres port = 5432")
cur = conn.cursor()
cur.execute("CREATE TABLE egg (num integer, data varchar);")
cur.execute("INSERT INTO egg values (1, 'A');")
conn.commit()
cur.execute("SELECT num from egg;")
row = cur.fetchone()
print row
cur.close()
conn.close()
testEgg()
而且我得到了错误:
psycopg2.OperationalError: FATAL: Ident authentication failed for user "postgres"
此代码运行良好,在windows7
却得到了上面提到的linux
错误。 有什么我需要做更多的在Linux?任何建议将不胜感激。 谢谢。
感谢您的信息,但是当我这样做时,也就是说,当我尝试创建用户时,仍然收到“Ident身份验证失败”错误,代码为:#createuser -S -D -R -E testUser createuser:无法连接到数据库postgres:FATAL:用户“root”的Ident认证失败 – 2011-05-11 13:27:21
当您与root用户连接时,只需磁带:“su - postgres”。然后,您可以轻松地运行createuser ... – 2011-05-11 15:06:43