rails和mysql数据库连接中出现的有关问题以及解决方法

rails和mysql数据库连接中出现的问题以及解决办法

发生环境
mysql for rails (2.8.1)
rails (2.2.2)
ruby 1.8.6
mysql (5.1.29-rc-win32)

 

问题描述
MySql数据库可以连接,并且与MySql相关的rails配置都正常。
但是在程序运行访问数据库时,服务器出现了如下的错误信息:
ArgumentError (NULL pointer given):
     (eval):3:in `each_hash'
     (eval):3:in `all_hashes'
....

或者

 

在rials工程目录下执行rake db:migrate --trace命令导入数据库结构时,发生如下的错误:

rake aborted!
Mysql::Error: query: not connected: CREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL) ENGINE=I
nnoDB

 

解决方案

Copy libmysql.dll from InstantRails (see below) to your mysql directory (your mysql directory\bin\) and system32 directory(C:\WINDOWS\system32).
Restart your computer and it should be working.

 

InstantRails libmysql.dll:
http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/

或者见附件(libmySQL.rar)