postgresql - 创建角色和数据库 PostgreSQL 不工作

标签 postgresql osx-snow-leopard

首先我运行命令:

sudo su _postgres

然后我运行命令:

create role mixeddrinks with createdb login password 'password1'

但它返回:

-bash: create: command not found

我对终端和 PostgreSQL 不是很熟悉,所以我不确定我做错了什么我正在尝试创建一个角色和一个数据库。

最佳答案

First I run the command sudo su _postgres, then I run the command create role mixeddrinks with createdb login password 'password1'

你混淆了 shell 命令和 psql 命令行。

如果要使用SQL,需要使用psql命令。 sudo su _postgres 是作为 _postgres 用户获取 unix 命令 shell 的低效方法。它不会为您提供 SQL shell。您可以从 unix 命令 shell 运行 unix 命令,如 psqlcreateuser 等。你可以知道你在命令 shell 中,因为提示看起来像这样:

postgres$ 

如果你想要一个 SQL shell,这样你就可以运行 CREATE USER 等命令,你需要运行 psql。如果你想要一个 super 用户 SQL shell,那将是这样的:

sudo -u _postgres psql

这会给你一个提示:

postgres=#

您可以在其中运行 SQL 命令。请记住,SQL 命令以分号结尾。

postgres=# create role mixeddrinks with createdb login password 'password1';

关于postgresql - 创建角色和数据库 PostgreSQL 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21151721/

相关文章:

cocoa arc4random OS X 10.6

macos - 我可以将非特权应用程序绑定(bind)到 Mac OS X 上的特权端口吗?

postgresql - (UndefinedFunctionError) 未定义函数 List.Chars.to_charlist/1

postgresql - 检测postgres中的特殊字符

python - psycopg2.connect 失败,错误为 'connection refused'(Django app+db 托管在单独的虚拟机上)

sql - 选择(列名)作为子查询

php - 显示另一个表中不存在的值

macos - 我的 boot2docker 安装似乎无法正常工作。我究竟做错了什么?

osx-lion - OSX "loginwindow"PAM 配置文件?

python - 是什么导致 Python "Interpreter not Initialized (version mismatch?)"错误?