如何在postgresql中创建数据库的用户? [英] How to create user for a db in postgresql?

查看:131
本文介绍了如何在postgresql中创建数据库的用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的CentOS服务器上安装了PostgreSQL 8.4,并从shell连接到root用户并访问PostgreSQL shell。



我在PostgreSQL中创建了数据库和用户。 / p>

尝试从我的PHP脚本连接时,显示我的身份验证失败。



如何创建新用户

解决方案

从CLI:

  $ su  -  postgres 
$ psql template1
template1 =#CREATE USER tester with PASSWORD'test_password';
template1 =#将所有特权授予数据库test_database以测试;
template1 =#\q



PHP PHP(在localhost上测试, ):

  $ connString ='port = 5432 dbname = test_database user = tester password = test_password'; 
$ connHandler = pg_connect($ connString);
echo'Connected to'.pg_dbname($ connHandler);


I have installed PostgreSQL 8.4 on my CentOS server and connected to root user from shell and accessing the PostgreSQL shell.

I created the database and user in PostgreSQL.

While trying to connect from my PHP script it shows me authentication failed.

How do I create a new user and how to grant permissions to them for a particular DB?

解决方案

From CLI:

$ su - postgres 
$ psql template1
template1=# CREATE USER tester WITH PASSWORD 'test_password';
template1=# GRANT ALL PRIVILEGES ON DATABASE "test_database" to tester;
template1=# \q

PHP (as tested on localhost, it works as expected):

  $connString = 'port=5432 dbname=test_database user=tester password=test_password';
  $connHandler = pg_connect($connString);
  echo 'Connected to '.pg_dbname($connHandler);

这篇关于如何在postgresql中创建数据库的用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆