標籤:border /var lis class apt-get help 終端 利用 lin
在 mac 下,可以利用 homebrew 直接安裝 PostgreSQL:
1 |
brew install postgresql - v |
稍等片刻,PostgreSQL 就安裝完成。接下來就是初始資料庫,在終端執行一下命令,初始配置 PostgreSQL:
1 |
initdb /usr/local/var/postgres -E utf8 |
上面指定 "/usr/local/var/postgres" 為 PostgreSQL 的配置資料存放目錄,並且設定資料庫資料編碼是 utf8,更多配置資訊可以 "initdb --help" 查看。
設成開機啟動 PostgreSQL:
12 |
ln -sfv /usr/local/opt/postgresql/ *.plist ~ /Library/LaunchAgents launchctl load ~ /Library/LaunchAgents/homebrew .mxcl.postgresql.plist |
啟動 PostgreSQL:
1 |
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server .log start |
關閉 PostgreSQL:
1 |
pg_ctl -D /usr/local/var/postgres stop -s -m fast |
建立一個 PostgreSQL 使用者
123 |
createuser username -P #Enter password for new role: #Enter it again: |
上面的 username 是使用者名稱,斷行符號輸入 2 次使用者密碼後即使用者建立完成。更多使用者建立資訊可以 "createuser --help" 查看。
建立資料庫
1 |
createdb dbname -O username -E UTF8 -e |
上面建立了一個名為 dbname 的資料庫,並指定 username 為改資料庫的擁有者(owner),資料庫的編碼(encoding)是 UTF8,參數 "-e" 是指把資料庫執行操作的命令顯示出來。
更多資料庫建立資訊可以 "createdb --help" 查看。
串連資料庫
1 |
psql -U username -d dbname -h 127.0.0.1 |
mac下安裝postgreSql