Ror项目与mysql数据库

来源:互联网 发布:淘宝厚底运动鞋正品店 编辑:程序博客网 时间:2024/06/06 10:02

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 下载 

mysql-connector-c-noinstall-6.0.2-win32.zip

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



原创粉丝点击