简体   繁体   English

在rails中连接现有的MySQL数据库

[英]Connect existing MySQL database in rails

I want to connect my Ruby on Rails application with a MySQL database, which was developed separately. 我想将我的Ruby on Rails应用程序与MySQL数据库连接,该数据库是单独开发的。 For this connection I used the development environment: 对于这种连接,我使用了development环境:

adapter: mysql
username: root  
password: ******  
host: 127.0.0.1
port: 3306   

When I try to make the MySQL connection in Rails it shows: 当我尝试在Rails中建立MySQL连接时,它显示:

C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql-2.9.0-x86-mingw32/lib/mysql.rb:4:in `require': Incorrect MySQL client library version! This gem was compiled for 6.0.0 but the client library is 5.5.9. (RuntimeError)
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql-2.9.0-x86-mingw32/lib/mysql.rb:4:in `<top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `each'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `block in require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `each'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler.rb:128:in `require'
    from D:/registration/config/application.rb:7:in `<top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:53:in `require'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:53:in `block in <top (required)>'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:50:in `tap'
    from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

D:\registration>

Also, when I try my rake command it shows: 此外,当我尝试我的rake命令时,它显示:

rake aborted!
Incorrect MySQL client library version! This gem was compiled for 6.0.0 but the client library is 5.5.9.
D:/registration/config/application.rb:7:in `<top (required)>'
D:/registration/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)

D:\registration>

How can I connect to my database? 我如何连接到我的数据库?

As per the error it seems like you are using a newer version of the gem than your MySQL client. 根据错误,您似乎使用的是比MySQL客户端更新的gem版本。

It says: 它说:

  • Your gem has been compiled (created with) my sql client version 6.0.0. 您的gem已经编译(使用)我的sql客户端版本6.0.0。
  • Your actual my sql client version (in your machine) is 5.5.9. 您的实际我的SQL客户端版本(在您的机器中)是5.5.9。

Could you post your MySQL gem version as well as your MySQL client version? 你可以发布你的MySQL gem版本以及你的MySQL客户端版本吗?

Upgrating your MySQL client to version 6.0.0 should fix this issue. 将MySQL客户端升级到版本6.0.0应该可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM