中指定DB名称
我已经包括了宝石,
dbd-mysql (0.4.4)
dbi (0.4.5)
mysql (2.8.1)
在rails控制台上,当我运行以下代码,
require 'rubygems'
require "dbi"
require 'dbd-mysql'
dbh = DBI.connect("DBI:Mysql:TestDB:localhost","username", "pwd")
1.9.2-p180 :001 > require 'rubygems'
=> false
1.9.2-p180 :002 > require "dbi"
=> false
1.9.2p180 :003 > require 'dbd-mysql'
LoadError: no such file to load -- dbd-mysql
from /.rvm/gems/ruby-1.9.2-p180@rails3/gems/dbi-0.4.5/lib/dbi.rb:318:in `rescue in load_driver'
from /.rvm/gems/ruby-1.9.2-p180@rails3/gems/dbi-0.4.5/lib/dbi.rb:242:in `load_driver'
from /.rvm/gems/ruby-1.9.2-p180@rails3/gems/dbi-0.4.5/lib/dbi.rb:160:in `_get_full_driver'
from /.rvm/gems/ruby-1.9.2-p180@rails3/gems/dbi-0.4.5/lib/dbi.rb:145:in `connect'
from (irb):3
from /.rvm/gems/ruby-1.9.2-p180@rails3/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start'
from /.rvm/gems/ruby-1.9.2-p180@rails3/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start'
from /.rvm/gems/ruby-1.9.2-p180@rails3/gems/railties-3.1.1/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
1.9.2-p180 :004 > dbh = DBI.connect("DBI:Mysql:TestDB:localhost","username", "pwd")
DBI::InterfaceError: Could not load driver (uninitialized constant MysqlError)
from /.rvm/gems/ruby-1.9.2-p180@rails3/gems/dbi-0.4.5/lib/dbi.rb:318:in `rescue in load_driver'
from /.rvm/gems/ruby-1.9.2-p180@rails3/gems/dbi-0.4.5/lib/dbi.rb:242:in `load_driver'
from /.rvm/gems/ruby-1.9.2-p180@rails3/gems/dbi-0.4.5/lib/dbi.rb:160:in `_get_full_driver'
from /.rvm/gems/ruby-1.9.2-p180@rails3/gems/dbi-0.4.5/lib/dbi.rb:145:in `connect'
from (irb):3
from /.rvm/gems/ruby-1.9.2-p180@rails3/gems/railties-3.1.1/lib/rails/commands/console.rb:45:in `start'
from /.rvm/gems/ruby-1.9.2-p180@rails3/gems/railties-3.1.1/lib/rails/commands/console.rb:8:in `start'
from /.rvm/gems/ruby-1.9.2-p180@rails3/gems/railties-3.1.1/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
1.9.2-p180 :004 >
我得到这个错误
LoadError: no such file to load -- dbd-mysql
DBI::InterfaceError: Could not load driver (uninitialized constant MysqlError)
是我的db -mysql gem没有正确安装吗?请问有人建议我如何解决这个问题吗?
如果我是你,我会用
创建一个全新的应用程序rails new ProjectName -d mysql
然后在Config/Database.yml