我使用 brew 在 mac 上安装了 postgresql。在安装过程中,我没有被问及 postgresql 的密码。现在我需要创建一个用户,但不能:
Alexs-MacBook-Air:mydir alex$ su - postgres
Password:
su: Sorry
无论我使用什么密码(包括空密码),它都是错误的。重置它的最简单方法是什么?
最佳答案
I installed postgresql on mac using brew. I wasn't asked about for the password for postgresql during the installation.
这很正常,因为 brew
不需要或创建任何 postgres
帐户。
PostgreSQL 进程在您自己的帐户下运行。到目前为止,其他 3 个答案在这方面是错误的。
有关信息,请参阅 brew info postgres
的输出。
要创建一个新的数据库帐户,您可以从您自己的操作系统帐户启动:
/usr/local/bin/createdb someusername
或在 psql 中:
/usr/local/bin/psql -d postgres
然后作为 SQL 命令:CREATE USER someusername PASSWORD 'somepassword';
这应该有效,因为 brew 通常在 initdb
时间创建:
- 一个数据库 super 用户帐户,与您的操作系统帐户具有相同的登录名(在您的情况下似乎是
alex
) - 一个名为
postgres
的数据库,可用于记录管理任务(例如创建用户)的信息。
使用完整路径 /usr/local/bin
的目的是为了访问 brew
提供的命令,而不是使用相同名称的命令与系统并位于 /usr/bin
或可能由其他 PostgreSQL 提供程序安装的具有相同名称的命令,例如 postgres.app 或 macports 或 entreprisedb。在 Mac OS X 上安装 postgresql 有 5-6 种相互竞争且不兼容的方法。
编辑:较新版本的 MacOS X 桌面版不再预装 postgres 客户端命令。至少从 MacOS X 10.10 (Yosemite) 和可能的 10.9 开始就是这种情况。
关于macos - 无法登录系统用户postgres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23982282/