windows上的PostgreSQL 12.0 Git Bash与createDB的斗争

windows上的PostgreSQL 12.0 Git Bash与createDB的斗争,postgresql,Postgresql,我已经在我的电脑上安装了postgresql,并试图通过git bash使用“createdb”函数。我只是好奇为什么它要问我一个密码,我想要的是我试图创建的数据库的名称。我可以确认我已经在我的电脑上启动并重新启动了postgresql 我的命令: $ psql createdb foo Password for user foo: <(not really sure what to put here)> createdb是一个与psql类似的命令行程序。传递给的第一个参数是,假定

我已经在我的电脑上安装了postgresql,并试图通过git bash使用“createdb”函数。我只是好奇为什么它要问我一个密码,我想要的是我试图创建的数据库的名称。我可以确认我已经在我的电脑上启动并重新启动了postgresql

我的命令:

$ psql createdb foo
Password for user foo: <(not really sure what to put here)>

createdb
是一个与
psql
类似的命令行程序。传递给的第一个参数是,假定为新数据库的名称。由于所有Postgres命令行客户端都假定当前操作系统用户为数据库用户,因此最好将超级用户显式传递给命令行程序。因此,要创建名为foo的数据库,请使用:

createdb -U postgres foo
或者从内部使用SQL命令创建数据库

psql -U postgres -d template1
template1=# create database foo;

我目前正在学习这个udacity课程,在线视频不需要在命令中包含“-u postgres”。我总是需要这样做有什么原因吗?@JackKoltermann“-U postgres”指定您以“postgres”用户身份登录。它将默认为您正在使用的用户帐户。在您的课程中,您可能会使用postgres帐户或您添加到database@a_horse_with_no_name如果用户有密码怎么办?@a-horse-with-no-name命令“createdb-U postgres demo”不起作用,花了很长时间,什么都不做我在Windows上使用git bash为什么是“git bash”?为什么不使用本机命令行(
cmd
)?毕竟,
createdb.exe
是一个标准的Windows可执行文件。
psql -U postgres -d template1
template1=# create database foo;