database 如何在 Windows 中将用户添加到 PostgreSQL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5189026/
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
How to add a user to PostgreSQL in Windows?
提问by Eric Wilson
I'm running PostgreSQL on mt Windows 7 machine. To run a database I type:
我在 mt Windows 7 机器上运行 PostgreSQL。要运行数据库,我输入:
C:\psql -Upostgres mydb
and this works, but it would be nice if I could leave off the -Ustuff, but then Postgres thinks I'm trying to log in as 'Eric', since that is my user profile.
这行得通,但如果我可以省略这些-U内容会很好,但是 Postgres 认为我正在尝试以“Eric”的身份登录,因为那是我的用户配置文件。
So I need to add a user to Postgres, obviously. But how? If I try:
所以显然我需要向 Postgres 添加一个用户。但是如何?如果我尝试:
C:\createuser Eric
Postgres thinks I'm trying to add a user Eric as the user Ericwhich fails. Adding the -Uflag doesn't seem to work here.
Postgres 认为我正在尝试将用户 Eric 添加为失败的用户 Eric。添加-U标志在这里似乎不起作用。
What am I missing? My command window is in administrator mode, and there is no sudoavailable, obviously.
我错过了什么?我的命令窗口处于管理员模式sudo,显然没有可用的。
回答by digitaljoel
In pgadmin you can create a new "Login Role" and name it Eric and give it permissions graphically, or from command line you can do something like this
在 pgadmin 中,您可以创建一个新的“登录角色”并将其命名为 Eric 并以图形方式为其授予权限,或者从命令行您可以执行以下操作
psql -U postgres -c "CREATE ROLE Eric LOGIN NOSUPERUSER INHERIT CREATEDB CREATEROLE;" mydb
see http://developer.postgresql.org/pgdocs/postgres/sql-createrole.htmlfor information on the CREATE ROLE options.
有关 CREATE ROLE 选项的信息,请参阅http://developer.postgresql.org/pgdocs/postgres/sql-createrole.html。
回答by Rayz
Just to add more information. From official documentation: you can specify the user under which createuser utility logs in to postgres via environment variable:
只是为了添加更多信息。从官方文档:您可以通过环境变量指定 createuser 实用程序登录到 postgres 的用户:
PGUSER
One liner for powershell:
一个用于 powershell 的衬垫:
& { $env:PGUSER="postgres"; .\createuser.exe Eric}
回答by Greg Hewgill
The documentation for createuserindicates that a -Uswitch is accepted:
的文档createuser表明-U接受了一个开关:
-U username--username usernameUser name to connect as (not the user name to create).
-U username--username username要连接的用户名(不是要创建的用户名)。
This is what I would expect to use (although I've never tried to set up PostgreSQL on Windows, only on unices).
这是我希望使用的(尽管我从未尝试在 Windows 上设置 PostgreSQL,只在 unices 上)。
回答by valkyrie55
This worked for me --username Shweta;
这对我有用 --username Shweta;
Now to create a database create database db;
现在创建一个数据库 create database db;

