简体   繁体   中英

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 ruby 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

只需安装mysql2 gem,然后在要创建新项目时运行

rails new APPNAME --database=mysql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM