---
title: "Rails2.2.2上安装mysql的adapter"
author: "xiaogui9317170"
date: "2009-02-24T12:23:05Z"
tags: ["ActiveRecord", "C", "MySQL", "Rails", "Ruby"]
slug: "rails2-2-2-mysql-adapter"
draft: false
lastmod: "2009-02-26T09:25:33Z"
id: 337869
url: "https://xiaogui9317170.iteye.com/blog/337869"
---

## Rails2.2.2上gem install mysql

环境：WindowsXP RadRails ruby1.8.2 rails2.2.2 mysql5.1.30

 

google一下，发现Rails2.2.2库不包括mysql适配器，需要自己安装。

 

第一尝试，直接运行

 

```
gem install mysql
```

 发现公司网络有代理，无法远程安装，本地安装又没找到相应的gem库，只好接着试。

 

 

接着，尝试安装mysql的jdbc适配器。

先从http://gems.rubyforge.vm.bytemark.co.uk/gems/上下载

[activerecord-jdbc-adapter-0.9.gem](http://gems.rubyforge.vm.bytemark.co.uk/gems/activerecord-jdbcmysql-adapter-0.9.gem) ，

[jdbc-mysql-5.0.4.gem](http://gems.rubyforge.vm.bytemark.co.uk/gems/jdbc-mysql-5.0.4.gem) ，

[activerecord-jdbcmysql-adapter-0.9.gem](http://gems.rubyforge.vm.bytemark.co.uk/gems/activerecord-jdbc-adapter-0.9.gem) 。

 

运行

 

```
gem install E:\study\Ruby_on_Rails\ruby-gems\activerecord-jdbcmysql-adapter-0.9.gem
gem install E:\study\Ruby_on_Rails\ruby-gems\activerecord-jdbc-adapter-0.9.gem
gem install E:\study\Ruby_on_Rails\ruby-gems\jdbc-mysql-5.0.4.gem
```

 

安装信息

&gt;gem install E:\\study\\Ruby\_on\_Rails\\ruby-gems\\jdbc-mysql-5.0.4.gem  
Successfully installed jdbc-mysql-5.0.4  
1 gem installed  
Installing ri documentation for jdbc-mysql-5.0.4...  
Installing RDoc documentation for jdbc-mysql-5.0.4...  
&gt;gem install E:\\study\\Ruby\_on\_Rails\\ruby-gems\\jdbc-mysql-5.0.4.gem  
Successfully installed jdbc-mysql-5.0.4  
1 gem installed  
Installing ri documentation for jdbc-mysql-5.0.4...  
Installing RDoc documentation for jdbc-mysql-5.0.4...  
&gt;gem install E:\\study\\Ruby\_on\_Rails\\ruby-gems\\activerecord-jdbcmysql-adapter-0.9.gem  
Successfully installed activerecord-jdbcmysql-adapter-0.9  
1 gem installed  
Installing ri documentation for activerecord-jdbcmysql-adapter-0.9...  
Installing RDoc documentation for activerecord-jdbcmysql-adapter-0.9...

 

运行

```
rake db:migrate
```

 

错误消息

&gt;rake db:migrate  
(in E:/workspace/studyRails)  
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.  
rake aborted!  
no such file to load -- mysql

(See full trace by running task with --trace)  
&gt;

 

根据提示，开启trace，运行

```
rake db:migrate --trace
```

 

&gt;rake db:migrate --trace  
rake db:migrate --trace  
(in E:/workspace/studyRails)  
\** Invoke db:migrate (first\_time)  
\** Invoke environment (first\_time)  
\** Execute environment  
\** Execute db:migrate  
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.  
rake aborted!  
no such file to load -- jdbc-mysql-5.0.4/lib/jdbc/mysql.rb  
C:/Ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in \`gem\_original\_require'  
C:/Ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in \`require'  
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active\_support/dependencies.rb:153:in \`require'  
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active\_support/dependencies.rb:521:in \`new\_constants\_in'  
C:/Ruby/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active\_support/dependencies.rb:153:in \`require'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/mysql\_adapter.rb:64:in \`mysql\_connection'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/abstract/connection\_pool.rb:223:in \`send'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/abstract/connection\_pool.rb:223:in \`new\_connection'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/abstract/connection\_pool.rb:245:in \`checkout\_new\_connection'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/abstract/connection\_pool.rb:188:in \`checkout'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/abstract/connection\_pool.rb:184:in \`loop'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/abstract/connection\_pool.rb:184:in \`checkout'  
C:/Ruby/lib/ruby/1.8/monitor.rb:242:in \`synchronize'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/abstract/connection\_pool.rb:183:in \`checkout'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/abstract/connection\_pool.rb:98:in \`connection'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/abstract/connection\_pool.rb:326:in \`retrieve\_connection'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/abstract/connection\_specification.rb:121:in \`retrieve\_connection'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/abstract/connection\_specification.rb:113:in \`connection'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/migration.rb:429:in \`initialize'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/migration.rb:394:in \`new'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/migration.rb:394:in \`up'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/migration.rb:377:in \`migrate'  
C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/tasks/databases.rake:111  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in \`call'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in \`execute'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in \`each'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in \`execute'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in \`invoke\_with\_call\_chain'  
C:/Ruby/lib/ruby/1.8/monitor.rb:242:in \`synchronize'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in \`invoke\_with\_call\_chain'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in \`invoke'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2019:in \`invoke\_task'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in \`top\_level'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in \`each'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in \`top\_level'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in \`standard\_exception\_handling'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1991:in \`top\_level'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1970:in \`run'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in \`standard\_exception\_handling'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1967:in \`run'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/bin/rake:31  
C:/Ruby/bin/rake:19:in \`load'  
C:/Ruby/bin/rake:19  
&gt;

 

注意这一行

C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/mysql\_adapter.rb:64:in \`mysql\_connection'

跟mysql配置有关系，根据进去，发现

```
# Require the MySQL driver and define Mysql::Result.all_hashes
      unless defined? Mysql
        begin
          require_library_or_gem('mysql')
        rescue LoadError
          $stderr.puts '!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.'
          raise
        end
      end
      MysqlCompat.define_all_hashes_method!
```

 上面的

```
require_library_or_gem('mysql')
```

装载mysql.rb时失败。

 

接着，根据安装的mysql的jdbc适配器的目录修改mysql\_adapter.rb中第63行

```
require_library_or_gem('mysql')
```

修改为

```
require 'jdbc/mysql'
```

继续运行

```
rake db:migrate --trace
```

出现错误信息 Mysql not loaded，至此好像进入死胡同。打开C:\\Ruby\\lib\\ruby\\gems\\1.8\\gems\\jdbc-mysql-5.0.4\\lib\\jdbc\\mysql.rb

```
module Jdbc
  module MySQL
    VERSION = "5.0.4"
  end
end
if RUBY_PLATFORM =~ /java/
  require "mysql-connector-java-#{Jdbc::MySQL::VERSION}-bin.jar"
else
  warn "jdbc-mysql is only for use with JRuby"
end
```

 mysql的JDBC适配器中的mysql.rb非常简单，清楚的表明

```
jdbc-mysql is only for use with JRuby
```

至此我发现自己一开始就错了，没有搞清楚环境就人云亦云的安装数据库适配器。（这也是网上一些文章的通病，对一些相关的东西交代不清楚，一不小心就着道了）

 

接着从http://gems.rubyforge.vm.bytemark.co.uk/gems/上下载了新的mysql适配器

[addressable-2.0.2.gem](http://gems.rubyforge.vm.bytemark.co.uk/gems/addressable-2.0.2.gem)

[extlib-0.9.10.gem](http://gems.rubyforge.vm.bytemark.co.uk/gems/extlib-0.9.10.gem)  
[data\_objects-0.9.11.gem](http://gems.rubyforge.vm.bytemark.co.uk/gems/data_objects-0.9.11.gem)  
[do\_mysql-0.9.11.gem](http://gems.rubyforge.vm.bytemark.co.uk/gems/do_mysql-0.9.11.gem)

 

继续安装

```
gem install E:\study\Ruby_on_Rails\ruby-gems\addressable-2.0.2.gem
gem install E:\study\Ruby_on_Rails\ruby-gems\extlib-0.9.10.gem
gem install E:\study\Ruby_on_Rails\ruby-gems\data_objects-0.9.11.gem
gem install E:\study\Ruby_on_Rails\ruby-gems\do_mysql-0.9.11.gem
```

 

错误消息

&gt;gem install E:\\study\\Ruby\_on\_Rails\\ruby-gems\\do\_mysql-0.9.11.gem  
ERROR:  http://gems.rubyforge.org/ does not appear to be a repository  
ERROR:  Error installing E:\\study\\Ruby\_on\_Rails\\ruby-gems\\do\_mysql-0.9.11.gem:  
    do\_mysql requires data\_objects (= 0.9.11, runtime)  
&gt;gem install E:\\study\\Ruby\_on\_Rails\\ruby-gems\\data\_objects-0.9.11.gem  
ERROR:  http://gems.rubyforge.org/ does not appear to be a repository  
ERROR:  Error installing E:\\study\\Ruby\_on\_Rails\\ruby-gems\\data\_objects-0.9.11.gem:  
    data\_objects requires addressable (~&gt; 2.0, runtime)  
&gt;gem install E:\\study\\Ruby\_on\_Rails\\ruby-gems\\addressable-2.0.2.gem  
Successfully installed addressable-2.0.2  
1 gem installed  
Installing ri documentation for addressable-2.0.2...  
Installing RDoc documentation for addressable-2.0.2...  
&gt;gem install E:\\study\\Ruby\_on\_Rails\\ruby-gems\\data\_objects-0.9.11.gem  
ERROR:  http://gems.rubyforge.org/ does not appear to be a repository  
ERROR:  Error installing E:\\study\\Ruby\_on\_Rails\\ruby-gems\\data\_objects-0.9.11.gem:  
    data\_objects requires extlib (~&gt; 0.9.9, runtime)  
&gt;gem install E:\\study\\Ruby\_on\_Rails\\ruby-gems\\extlib-0.9.10.gem

&gt;gem install E:\\study\\Ruby\_on\_Rails\\ruby-gems\\extlib-0.9.10.gem

Successfully installed extlib-0.9.10  
1 gem installed  
&gt;gem install E:\\study\\Ruby\_on\_Rails\\ruby-gems\\data\_objects-0.9.11.gem  
ERROR:  http://gems.rubyforge.org/ does not appear to be a repository  
Successfully installed data\_objects-0.9.11  
1 gem installed  
Installing ri documentation for data\_objects-0.9.11...  
Installing RDoc documentation for data\_objects-0.9.11...  
&gt;gem install E:\\study\\Ruby\_on\_Rails\\ruby-gems\\do\_mysql-0.9.11.gem  
ERROR:  http://gems.rubyforge.org/ does not appear to be a repository  
Building native extensions.  This could take a while...  
ERROR:  Error installing E:\\study\\Ruby\_on\_Rails\\ruby-gems\\do\_mysql-0.9.11.gem:  
    ERROR: Failed to build gem native extension.

C:/Ruby/bin/ruby.exe extconf.rb install E:\\study\\Ruby\_on\_Rails\\ruby-gems\\do\_mysql-0.9.11.gem  
checking for mysql.h... no  
checking for main() in libmysql.lib... no  
checking for mysql\_query() in mysql.h... no  
\*\** extconf.rb failed \*\**  
Could not create Makefile due to some reason, probably lack of  
necessary libraries and/or headers.  Check the mkmf.log file for more  
details.  You may need configuration options.

Provided configuration options:  
    --with-opt-dir  
    --without-opt-dir  
    --with-opt-include  
    --without-opt-include=${opt-dir}/include  
    --with-opt-lib  
    --without-opt-lib=${opt-dir}/lib  
    --with-make-prog  
    --srcdir=.  
    --curdir  
    --ruby=C:/Ruby/bin/ruby  
    --with-mysql-dir  
    --without-mysql-dir  
    --with-mysql-include  
    --without-mysql-include=${mysql-dir}/include  
    --with-mysql-lib  
    --without-mysql-lib=${mysql-dir}/lib  
    --with-libmysqllib  
    --without-libmysqllib

Gem files will remain installed in C:/Ruby/lib/ruby/gems/1.8/gems/do\_mysql-0.9.11 for inspection.  
Results logged to C:/Ruby/lib/ruby/gems/1.8/gems/do\_mysql-0.9.11/ext/do\_mysql\_ext/gem\_make.out  
&gt;gem install E:\\study\\Ruby\_on\_Rails\\ruby-gems\\do\_mysql-0.9.11.gem  
ERROR:  http://gems.rubyforge.org/ does not appear to be a repository  
Building native extensions.  This could take a while...  
ERROR:  Error installing E:\\study\\Ruby\_on\_Rails\\ruby-gems\\do\_mysql-0.9.11.gem:  
    ERROR: Failed to build gem native extension.

C:/Ruby/bin/ruby.exe extconf.rb install E:\\study\\Ruby\_on\_Rails\\ruby-gems\\do\_mysql-0.9.11.gem  
checking for mysql.h... no  
checking for main() in libmysql.lib... no  
checking for mysql\_query() in mysql.h... no  
\*\** extconf.rb failed \*\**  
Could not create Makefile due to some reason, probably lack of  
necessary libraries and/or headers.  Check the mkmf.log file for more  
details.  You may need configuration options.

Provided configuration options:  
    --with-opt-dir  
    --without-opt-dir  
    --with-opt-include  
    --without-opt-include=${opt-dir}/include  
    --with-opt-lib  
    --without-opt-lib=${opt-dir}/lib  
    --with-make-prog  
    --srcdir=.  
    --curdir  
    --ruby=C:/Ruby/bin/ruby  
    --with-mysql-dir  
    --without-mysql-dir  
    --with-mysql-include  
    --without-mysql-include=${mysql-dir}/include  
    --with-mysql-lib  
    --without-mysql-lib=${mysql-dir}/lib  
    --with-libmysqllib  
    --without-libmysqllib

Gem files will remain installed in C:/Ruby/lib/ruby/gems/1.8/gems/do\_mysql-0.9.11 for inspection.  
Results logged to C:/Ruby/lib/ruby/gems/1.8/gems/do\_mysql-0.9.11/ext/do\_mysql\_ext/gem\_make.out

 

 

在windows下安装do-mysql有点困难。

 

没办法，只好把电脑带回家，继续第一次尝试。这一次成功了，但是输出

 

&gt;gem install mysql

Successfully installed mysql-2.7.3-x86-mswin32

1 gem installed

Installing ri documentation for mysql-2.7.3-x86-mswin32...

Installing RDoc documentation for mysql-2.7.3-x86-mswin32...

ERROR:  While generating documentation for mysql-2.7.3-x86-mswin32

... MESSAGE:   Unhandled special: Special: type=17, text="&lt;!-- $Id: README.html,v 1.20 2006-12-20 05:31:52 tommy Exp $ --&gt;"

... RDOC args: --op C:/Ruby/lib/ruby/gems/1.8/doc/mysql-2.7.3-x86-mswin32/rdoc --exclude ext --main README --quiet ext README docs/README.html

(continuing with the rest of the installation)

 

 

 

这表明库已经安装成功，但是rdoc安装失败了，不影响使用。

 

 

继续测试

 

```
script/generate scaffold article title:string article:text
```

 

 

exists app/models/

exists app/controllers/

exists app/helpers/

create app/views/articles

exists app/views/layouts/

exists test/functional/

exists test/unit/

exists public/stylesheets/

create app/views/articles/index.html.erb

create app/views/articles/show.html.erb

create app/views/articles/new.html.erb

create app/views/articles/edit.html.erb

create app/views/layouts/articles.html.erb

create public/stylesheets/scaffold.css

create app/controllers/articles\_controller.rb

create test/functional/articles\_controller\_test.rb

create app/helpers/articles\_helper.rb

route map.resources :articles

dependency model

exists app/models/

exists test/unit/

exists test/fixtures/

create app/models/article.rb

create test/unit/article\_test.rb

create test/fixtures/articles.yml

create db/migrate

create db/migrate/20090225144729\_create\_articles.rb

 

 

 产生相应的骨架后，

 

```
rake db:migrate
```

 

 出错

 

&gt;rake db:migrate 

(in E:/workspace/studyRails)

rake aborted!

Mysql::Error: Commands out of sync; you can't run this command now: SHOW TABLES

 

(See full trace by running task with --trace)

&gt;

 

通过

```
gem list --local
```

 &gt;gem list --local  
actionmailer (2.2.2)  
actionpack (2.2.2)  
activerecord (2.2.2)  
activerecord-jdbc-adapter (0.9)  
activerecord-jdbcmysql-adapter (0.9)  
activeresource (2.2.2)  
activesupport (2.2.2)  
addressable (2.0.2)  
cgi\_multipart\_eof\_fix (2.5.0)  
data\_objects (0.9.11)  
extlib (0.9.10)  
fxri (0.3.6)  
fxruby (1.6.16)  
gem\_plugin (0.2.3)  
hpricot (0.6.164)  
jdbc-mysql (5.0.4)  
linecache (0.43)  
log4r (1.0.5)  
mongrel (1.1.5)  
mysql (2.7.3)  
ptools (1.1.6)  
rails (2.2.2)  
rake (0.8.3, 0.8.1)  
ruby-debug-base (0.10.3)  
ruby-debug-ide (0.4.2)  
ruby-opengl (0.60.0)  
test-unit (2.0.1)  
win32-api (1.2.1, 1.2.0)  
win32-clipboard (0.4.4)  
win32-dir (0.3.2)  
win32-eventlog (0.5.0)  
win32-file (0.5.5)  
win32-file-stat (1.3.1)  
win32-process (0.5.9)  
win32-sapi (0.1.4)  
win32-sound (0.4.1)  
windows-api (0.2.4)  
windows-pr (0.9.3)  
&gt;

 

发现mysql库的版本为2.7.3，猜测是不是mysql版本跟库不匹配造成？ 

 

查询mysql的帮助文档

Commands out of sync in client错误

如果你在你的客户代码中得到`Commands out of sync; You can't run this command now` ，你正在以错误的次序调用客户函数！

这可能发生，例如，如果你正在使用`mysql_use_result()` 并且在你已经调用了`mysql_free_result()` 之前试图执行新查询。如果你在`mysql_use_result()` 或`mysql_store_result()` 之间试图执行返回数据的2个查询，它也可能发生。

 

 通过trace跟踪

```
rake db:migrate --trace
```

 

&gt;rake db:migrate --trace  
(in E:/workspace/studyRails)  
\** Invoke db:migrate (first\_time)  
\** Invoke environment (first\_time)  
\** Execute environment  
\** Execute db:migrate  
\** Invoke db:schema:dump (first\_time)  
\** Invoke environment  
\** Execute db:schema:dump  
rake aborted!  
Mysql::Error: Commands out of sync; you can't run this command now: SHOW TABLES  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/abstract\_adapter.rb:188:in \`log'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/mysql\_adapter.rb:309:in \`execute'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/connection\_adapters/mysql\_adapter.rb:414:in \`tables'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/schema\_dumper.rb:61:in \`tables'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/schema\_dumper.rb:23:in \`dump'  
C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/schema\_dumper.rb:17:in \`dump'  
C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/tasks/databases.rake:246  
C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/tasks/databases.rake:245:in \`open'  
C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/tasks/databases.rake:245  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in \`call'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in \`execute'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in \`each'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in \`execute'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in \`invoke\_with\_call\_chain'  
C:/Ruby/lib/ruby/1.8/monitor.rb:242:in \`synchronize'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in \`invoke\_with\_call\_chain'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in \`invoke'  
C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/tasks/databases.rake:112  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in \`call'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in \`execute'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in \`each'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in \`execute'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in \`invoke\_with\_call\_chain'  
C:/Ruby/lib/ruby/1.8/monitor.rb:242:in \`synchronize'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in \`invoke\_with\_call\_chain'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in \`invoke'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2019:in \`invoke\_task'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in \`top\_level'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in \`each'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in \`top\_level'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in \`standard\_exception\_handling'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1991:in \`top\_level'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1970:in \`run'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in \`standard\_exception\_handling'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:1967:in \`run'  
C:/Ruby/lib/ruby/gems/1.8/gems/rake-0.8.3/bin/rake:31  
C:/Ruby/bin/rake:19:in \`load'  
C:/Ruby/bin/rake:19  
&gt;

 

发现出错的地方位于mysql\_adapter.rb:414，代码

```
    def tables(name = nil) #:nodoc:
        tables = []
        execute("SHOW TABLES", name).each { |field| tables << field[0] } #414行
        tables
      end
```

 

 为什么出这个错呢？猜测是mysql的库不匹配，先前把%MYSQL\_HOME%/bin下的libmySQL.dll复制到%RUBY\_HOME%/bin目录下，根据推测，用InstantRails-2.0-win.zip下的libmySQL.dll替换，再次跑db:migrate，果真一切ok。

 

真可谓一波三折矣！