yankj12 / blog

技术研究、管理实践、其他的一些文章
MIT License
1 stars 2 forks source link

Postgres数据库忘记密码(windows下举例) #69

Open yankj12 opened 4 years ago

yankj12 commented 4 years ago

一、修改data目录下的 pg_hba.conf 文件

将以下面md5改为trust。IPv4和IPv6都改为trust

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

重启pg (在我的电脑\管理\服务 中找)

二、运行cmd,进入postgres安装路径的bin目录,运行如下命令:

psql -U postgres

postgres=# alter user postgres with password '你要设置的密码';

postgres=# \q

三、修改data目录下的 pg_hba.conf 文件

将以下面md5改为trust。IPv4和IPv6都改为md5

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

重新启动postgres

参考

Postgres数据库忘记密码,三个步骤解决-windows下