1.安裝
brew install postgresql
2.初始化數據庫
initdb /usr/local/var/postgres -E utf8
3.設置開機啓動(可不設置)
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
4.啓動postgresql服務
brew services start postgresql
5.關閉postgresql服務
brew services start postgresql
6.建立一個用戶
createuser root -P
而後輸密碼
7.建立一個數據庫
建立了一個名爲 dbname 的數據庫,並指定 username 爲改數據庫的擁有者(owner),數據庫的編碼(encoding)是 UTF8,參數 "-e" 是指把數據庫執行操做的命令顯示出來。
createdb dbname -O root -E UTF8 -e
8.連接數據庫
psql -U username -d dbname -h 127.0.0.1