我已经在我的 CentOS 服务器上安装了 PostgreSQL 8.4,并从 shell 连接到 root 用户并访问 PostgreSQL shell。
我在 PostgreSQL 中创建了数据库和用户。
尝试从我的 PHP 脚本连接时,它显示身份验证失败。
如何创建新用户以及如何向他们授予特定数据库的权限?
最佳答案
来自 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(在 localhost 上测试过,它按预期工作):
$connString = 'port=5432 dbname=test_database user=tester password=test_password';
$connHandler = pg_connect($connString);
echo 'Connected to '.pg_dbname($connHandler);
关于database - 如何在 postgresql 中为数据库创建用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10861260/