使用 bash 命令在 postgresql 中创建数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47039732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:34:11  来源:igfitidea点击:

create database in postgresql with bash command

sqlbashpostgresqlubuntupsql

提问by pinug

Im trying to create a database in postgresql using linux.
I connected to postgres with

我正在尝试使用 linux 在 postgresql 中创建一个数据库。
我连接到 postgres

sudo -u postgres psql postgres 
postgres=# then i tried **CREATE DATABASE demo** or **createdb demo**

but none of them worked when i checked with \lcommand.
Any help ?

但是当我用\l命令检查时,它们都没有工作。
有什么帮助吗?

回答by Vao Tsun

sudo su - postgresto become postgres

sudo su - postgres成为 postgres

then psql -c "create database demo"to create it from shell

然后psql -c "create database demo"从shell创建它

回答by omar ahmed

first:

第一的:

    sudo su postgres

and then enter your password then type:

然后输入您的密码,然后键入:

     psql

and type this command:

并输入以下命令:

    CREATE DATABASE dbname;

回答by mehdi mosavi

simple type on bash

bash 上的简单类型

$ createdb -U postgres(db user) dbname

$ createdb -U postgres(db user) dbname

if set hba_config in pg for access to db in network type

如果在 pg 中设置 hba_config 以访问网络类型中的 db

$ createdb -h YOUR_IP -U postgres(db user) dbname

$ createdb -h YOUR_IP -U postgres(db user) dbname

if you set password for db user pg ask your password to create database

如果您为 db 用户 pg 设置密码,请询问您的密码以创建数据库