开发者

Connecting Ruby and MySQL

I am in windows 7 and I installed ruby 1.9.2p180 and MySQL 5.5.15 and mysql gem. now how can I connect ru开发者_开发百科by to mysql ?


You can create a new rails app with mysql instead of the default sqlite by using:

rails new APPNAME -d mysql

Or the long form:

rails new APPNAME --database=mysql

You can then take a look at the generated file config/database.yml to see the settings used for mysql. You will need to set up your username, password and database in here. Don't forget that with mysql, you will need to create the database manually for each environment.

Sample config/database.yml:

development:
    adapter: mysql
    encoding: utf8
    reconnect: false
    database: test_database
    pool: 20
    username: root
    password: root
    host: localhost
    socket: /var/run/mysqld/mysqld.sock


Just install mysql2 gem and when you want to create a new project run

rails new APPNAME --database=mysql
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜