mac下安裝postgreSql

來源:互聯網
上載者:User

標籤: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/LaunchAgentslaunchctl 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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.