use*_*734 63 authentication passwords postgresql ident
在薄荷ubuntu上新安装了postgres 8.4.如何使用psql为postgres创建用户并登录?
当我输入psql时,它只是告诉我
psql: FATAL: Ident authentication failed for user "my-ubuntu-username"
Run Code Online (Sandbox Code Playgroud)
Eva*_*oll 102
您可以使用两种方法.两者都需要创建用户和数据库.
使用createuser和createdb,
$ sudo -u postgres createuser -s $USER
$ createdb mydatabase
$ psql -d mydatabase
Run Code Online (Sandbox Code Playgroud)使用SQL管理命令,并通过TCP连接密码
$ sudo -u postgres createuser -s $USER
$ createdb
$ psql
Run Code Online (Sandbox Code Playgroud)
然后,在psql shell中
$ sudo -u postgres psql postgres
Run Code Online (Sandbox Code Playgroud)
然后你可以登录,
CREATE ROLE myuser LOGIN PASSWORD 'mypass';
CREATE DATABASE mydatabase WITH OWNER = myuser;
Run Code Online (Sandbox Code Playgroud)
如果您不知道端口,可以通过以mydatabase用户身份运行以下命令来获取端口
$ psql -h localhost -d mydatabase -U myuser -p <port>
Run Code Online (Sandbox Code Playgroud)
要么,
SHOW port;
Run Code Online (Sandbox Code Playgroud)postgres用户我建议不要修改postgres用户.
postgres.你应该有root来进行身份验证postgres.postgresPostgreSQL等效的SQL Server postgres,您必须具有对底层数据文件的写访问权.而且,这意味着无论如何你通常都会破坏混乱.use*_*976 37
默认情况下,您需要使用postgres用户:
sudo -u postgres psql postgres
Run Code Online (Sandbox Code Playgroud)
cop*_*360 17
您得到的错误是因为您的-ubuntu-username不是有效的Postgres用户.
你需要告诉psql使用什么数据库用户名
psql -U postgres
Run Code Online (Sandbox Code Playgroud)
您可能还需要指定要连接的数据库
psql -U postgres -d <dbname>
Run Code Online (Sandbox Code Playgroud)
使用 postgres 用户或我们创建的任何其他用户登录的主要区别在于,当使用 postgres 用户时,不需要使用-h指定主机,而是使用其他用户 if。
$ psql -U postgres
Run Code Online (Sandbox Code Playgroud)
# CREATE ROLE usertest LOGIN PASSWORD 'pwtest';
# CREATE DATABASE dbtest WITH OWNER = usertest;
# SHOW port;
# \q
$ psql -h localhost -d dbtest -U usertest -p 5432
Run Code Online (Sandbox Code Playgroud)
GL
小智 5
您还可以以“普通”用户(不是postgres)连接到数据库:
postgres=# \connect opensim Opensim_Tester localhost;
Password for user Opensim_Tester:
You are now connected to database "opensim" as user "Opensim_Tester" on host "localhost" at port "5432"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
96620 次 |
| 最近记录: |