Ror项目与mysql数据库

rails new blog 创建项目,修改config/database.yml

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: blog_development
  pool: 5
  username: dbuser
  password: dbuser
  host: localhost

cd blog进入项目目录

rake db:create 命令出现报错:

F:\Ruby\blog>rake db:migrate
rake aborted!
Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (my
sql2 is not part of the bundle. Add it to Gemfile.)


Tasks: TOP => db:migrate => db:load_config
(See full trace by running task with --trace)

搜索找到原因:新建项目是用 rails new blog -d mysql 重建项目立马解决。(或者编辑项目下Gemfile文件)


接着 rake db:create 命令,仍然报错:

F:\Ruby\blog>rake db:migrate
rake aborted!
Incorrect MySQL client library version! This gem was compiled for 6.0.0 but the
client library is 5.5.9.


(See full trace by running task with --trace)
这算说得很明白了,lib版本不对。 接着搜索,找到解决方案:

When run rails server,get the error(already install newest RailsInstaller of windows xp and mysql2-0.3.11-x86-mingw32) :

d:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/mysql2.rb:2:in `require': Incorrect MySQL client library version! This gem was compiled for 6.0.0 but the client library is 5.0.16. (RuntimeError)......

There is a easy way to let RailsInstaller(Ruby1.9.2)  use mysql-connector-c-6.

(1)download mysql-connector-c-noinstall-6.0.2-win32.zip
http://dev.mysql.com/downloads/mirror.php?id=377978

(2)Unzip the mysql-connector-c-noinstall-6.0.2-win32.zip and copu mysql-connector-c-noinstall-6.0.2-win32\lib\libmysql.dll to RailsInstaller\Ruby1.9.2\bin

Then run rails server,every thing is ok.

http://dev.mysql.com/downloads/mirror.php?id=377978 下载 

下载后 解压把lib目录里的 libmysql.dll复制到 ruby/bin目录。再rake,问题解决。



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值