首页 文章

从命令行或VBScript在Windows中创建数据库?

提问于
浏览
-2

如何从Windows命令行或VBScript为PostgreSQL 10(pgAdmin 4)创建新数据库?

我在命令行中使用了以下命令:

pg_dump --dbname=postgresql://postgres:123@localhost:5432/myDB --format=p --clean

但它返回了以下错误:

pg_dump:[archiver(db)]与数据库“myDB”的连接失败:无法连接到服务器:连接被拒绝(0x0000274D / 10061)服务器是否在主机“localhost”(:: 1)上运行并接受TCP / IP连接在5432港口?无法连接到服务器:连接被拒绝(0x0000274D / 10061)服务器是否在主机“localhost”(127.0.0.1)上运行并接受端口5432上的TCP / IP连接?

如何在“localhost”(127.0.0.1)中运行服务器?如何解决这个问题?

EDIT: 此外,我也尝试过这个,

createdb --dbname=postgresql://postgres:123@localhost:5432/myDB --format=p --clean

得到了这个错误,

createdb:非法选项 - dbname = postgresql:// postgres:123 @ localhost:5432 / myDB尝试“createdb --help”获取更多信息 .

1 回答

  • 0

    感谢JasenMladen Uzelac,我在here找到了解决方案 . 这是创建数据库的命令行,

    cd "C:\Program Files (x86)\PostgreSQL\10\bin"
    psql -c "CREATE DATABASE mydb" "user=postgres dbname=postgres password=something_secret"
    

相关问题