顯示具有 Rails 標籤的文章。 顯示所有文章
顯示具有 Rails 標籤的文章。 顯示所有文章

2015年9月16日 星期三

Mac安裝PostgreSQL與簡單教學

PostgreSQL和MySQL一樣都是一種SQL Server
以下有些教學是可以提供給會MySQL,也想使用PostgreSQL的使用者看看

第零步,安裝PostgreSQL

使用brew來安裝 (Linux的話就看是apt / yum 還是什麼的,以下以Mac為例)

brew install postgresql

成功的話,會看到最後有段訊息

To have launchd start postgresql at login:
  ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
  launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
  postgres -D /usr/local/var/postgres


主要的重點是說,你想要一登入Mac的使用者,就自動啟動PostgreSQL的話,就在終端機輸入


ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

要手動啟動 (第一次裝完最好也輸入一次)

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

如果想要停止的話輸入

postgres -D /usr/local/var/postgres




第一步,建立Database
createdb 是 postgresql 建立資料庫的指令

2015年9月1日 星期二

Ruby on Rails 連結MAMP的MySQL教學 (Mac適用)


Mac要先安裝Mysql (透過brew),指令如下:

brew install mysql

再來是到Rails中安裝mysql的gem,進到目錄下編輯Gemfile,加入這行

gem 'mysql2'

然後

bundle install

可以先到MAMP的phpMyAdmin建立好一個資料庫和User來使用
(MAMP預設的phpMyAdmin位置是 http://localhost:8888/phpMyAdmin/ )

參考以下步驟