Postgresql 创建数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5735370/
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-10 22:55:50  来源:igfitidea点击:

Postgresql creating database

postgresql

提问by Jaanus

Well I installed the latest postgreql database on my Windows 7.

好吧,我在 Windows 7 上安装了最新的 postgreql 数据库。

Now I'm trying to create a database via the psql.exe command line

现在我正在尝试通过 psql.exe 命令行创建一个数据库

When I open it, it says

当我打开它时,它说

psql: FATAL: database "Jansu" does not exist

So I read somewhere, that when no database is specified, it tried to find database with my username or something.

所以我在某处读到,当没有指定数据库时,它试图用我的用户名或其他东西查找数据库。

Anyways..how do i create a new database, when I can't access the commandline.

无论如何......当我无法访问命令行时,我该如何创建一个新数据库。

回答by leonbloy

Read psql syntax. You can specify database, user and other parameters. If it's a new installation, there should be a default database 'postgres', you can connect to that one.

阅读psql 语法。您可以指定数据库、用户和其他参数。如果是全新安装,则应该有一个默认数据库“postgres”,您可以连接到该数据库。

 psql -U postgres postgres 

(In Unix environments you might need to add -h localhostin order to force a TCP connection, otherwise it'd try to use Unix-domain sockets, which might not work for other than the postgresuser. )

(在 Unix 环境中,您可能需要添加-h localhost以强制 TCP 连接,否则它会尝试使用 Unix 域套接字,这可能不适用于postgres用户以外的其他人。)

You can create databases from there, or from the command line with createdb

您可以从那里创建数据库,也可以从命令行使用createdb