抓虾

ZhuaXia.xyz


  • 首页

  • 标签

  • 导航

mac使用homebrew安装 PostgreSQL

发表于 2022-03-21 标签| blog postgreSQL mac

在mac利用 homebrew直接安装 PostgreSQL:

brew install postgresql -v

稍等片刻,PostgreSQL 就安装完成。接下来就是初始数据库,在终端执行一下命令,初始配置 PostgreSQL:

initdb /usr/local/var/postgres -E utf8

指定 "/usr/local/var/postgres" 为 PostgreSQL 的配置数据存放目录,并且设置数据库数据编码是 utf8,更多配置信息可以 "initdb --help" 查看。

如果需要,可以设成开机启动 PostgreSQL:

ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

 

常用命令

1、启动 PostgreSQL:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

 

2、关闭 PostgreSQL:

pg_ctl -D /usr/local/var/postgres stop -s -m fast

创建一个 PostgreSQL 用户

createuser testname -P
#Enter password for new role:
#Enter it again:

上面的 testname 是用户名

3、创建数据库

createdb testdb -O testname -E UTF8 -e

创建testdb数据库,并指定testname为这个数据库的owner,数据库的编码(encoding)是 UTF8,参数 "-e" 是指把数据库执行操作的命令显示出来。

4、连接数据库

psql -U username -d dbname -h 127.0.0.1 


相关文章

  • 如何使用 Homebrew 在 Mac 上同时安装 Python 2 和 3?
  • 国内源安装Homebrew
  • 如何从 Homebrew 重新安装 python@2?
  • python - 无法安装 TensorFlow Mac
  • python - 如何在 Mac OS 上使用 pip 安装 PIL?
  • 如何在 Mac 上安装 Java 8
  • python - 为 Mac OS X 10.6.8 安装 Pygame
  • 如何使用 Python 3 在 Mac 上安装 pyaudio?
  • 在 Mac OS X 上安装 MySQL Python
  • Python 3.3 和在 Mac 上安装 PyOpenSSL
使用 PIL 和 win32clipboard 在 python 中将图像写入 Windows 剪贴板?
如何通过 Python 抓取动态网页
© 2020-2021 ZhuaXia.xyz
修改自 NexT.Pisces 主题
licensed under cc by-sa 3.0
0%