如何解决Mikro-orm错误:用户“ postgres”的密码身份验证失败
我正在尝试与此React GraphQL TypeScript tutorial
一起编码该项目使用MikroOrm与PostgreSQL数据库进行通信。我在Ubuntu 18.04上安装了PostgreSQL(12.4),创建了一个“ postgres”用户,我可以登录该用户并运行</head>
<body>
<div class="topnav">
<a href="#">Link</a>
<a href="#">Link</a>
<a href="#">Link</a>
</div>
<div class="card">
<label for="ticker">Ticker(s):</label>
<input type="text" id="ticker" name="ticker" value="" style="text-transform:uppercase"><br>
</div>
<div class="row">
<div class="column">
<h2>Column</h2>
<p>INPUT INFO LATER INPUT INFO LATER</p>
</div>
<div class="column">
<h2>Column</h2>
<p>INPUT INFO LATER</p>
</div>
<div class="column">
<h2>Column</h2>
<p>INPUT INFO LATER</p>
</div>
</div>
</body>
</html>
,没有任何问题。但是,当我开始使用psql
(video timestamp)之类的mikro-orm
命令时,出现以下错误:
npx mikro-orm migration:create
这是PostgreSQL日志文件中的错误:
error: password authentication failed for user "postgres"
at Parser.parseErrorMessage (/home/<username>/newstack/node_modules/pg-protocol/src/parser.ts:357:11)
at Parser.handlePacket (/home/<username>/newstack/node_modules/pg-protocol/src/parser.ts:186:21)
at Parser.parse (/home/<username>/newstack/node_modules/pg-protocol/src/parser.ts:101:30)
at Socket.<anonymous> (/home/<username>/newstack/node_modules/pg-protocol/src/index.ts:7:48)
at Socket.emit (events.js:315:20)
at Socket.EventEmitter.emit (domain.js:483:12)
at addChunk (_stream_readable.js:295:12)
at readableAddChunk (_stream_readable.js:271:9)
at Socket.Readable.push (_stream_readable.js:212:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
length: 104,severity: 'FATAL',code: '28P01',detail: undefined,hint: undefined,position: undefined,internalPosition: undefined,internalQuery: undefined,where: undefined,schema: undefined,table: undefined,column: undefined,dataType: undefined,constraint: undefined,file: 'auth.c',line: '333',routine: 'auth_failed'
}
这是我的pg_hba.conf:
2020-08-28 01:45:18.218 EEST [23088] postgres@newstack FATAL: password authentication failed for user "postgres"
2020-08-28 01:45:18.218 EEST [23088] postgres@newstack DETAIL: Password does not match for user "postgres".
Connection matched pg_hba.conf line 96: "host all all 127.0.0.1/32 md5"
我已经知道,如果连接是本地连接,则不需要密码,但是为什么不使用本地套接字呢?如果无法更改,那我该如何给MikroOrm我的数据库凭据?
解决方法
像这样将“ md5”更改为“ trust”:
local all all peer
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
,
对我来说,添加后就可以使用
clientUrl: 'http://localhost:5433'
user: 'postgres',password: <user pasword for postgres user>
在选项对象中
,This 解决方案对我有用。将 user
和 password
道具添加到 mikro-orm 配置:
dbName: "lireddit",user: "<user_name>",password: "<password>",
,
确保将 ts-node 安装为 devDep
npm i -D ts-node
并将您的 postgres 用户名和密码作为属性放入 mikro-orm.config.ts 文件
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。