首先我运行命令:
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 commandcreate role mixeddrinks with createdb login password 'password1'
你混淆了 shell 命令和 psql
命令行。
如果要使用SQL,需要使用psql
命令。 sudo su _postgres
是作为 _postgres
用户获取 unix 命令 shell 的低效方法。它不会为您提供 SQL shell。您可以从 unix 命令 shell 运行 unix 命令,如 psql
、createuser
等。你可以知道你在命令 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/