我是铁轨上的红宝石新手。并尝试连接mysql服务器。我尝试与wamp连接,但没有工作。现在我做了什么,我只是将libmsql.dll文件复制到我的ruby bin目录。但我仍然无法与服务器连接。这是错误信息。谁能告诉我什么错了?
Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\row>cd dev
C:\row\dev>dir
Volume in drive C has no label.
Volume Serial Number is F223-E79C
Directory of C:\row\dev
09/27/2016 04:02 AM <DIR> .
09/27/2016 04:02 AM <DIR> ..
09/27/2016 04:03 AM <DIR> mysql_test
0 File(s)
0 bytes
3 Dir(s)
37,122,785,280 bytes free
C:\row\dev>cd mysql_test
C:\row\dev\mysql_test>ruby test.rb
C:/row/Ruby22/lib/ruby/gems/2.2.0/gems/mysql2-0.4.4-x86-mingw32/lib/mysql2/clien t.rb:87:in `connect': Can't connect to MySQL server on 'localhost' (10061) (Mysq l2::Error)
from C:/row/Ruby22/lib/ruby/gems/2.2.0/gems/mysql2-0.4.4-x86-mingw32/lib /mysql2/client.rb:87:in `initialize'
from test.rb:3:in `new'
from test.rb:3:in `<main>'
C:\row\dev\mysql_test>
答案 0 :(得分:0)
要将mysql数据库连接到rails,您必须对配置文件config/database.yml
进行一些更改。
您必须安装gem然后连接到mysql DB。
production:
adapter: mysql2
encoding: utf8
database: example
pool: 10
username: example
password: secure
socket: /var/run/mysqld/mysqld.sock
reconnect: true
除此之外,您还必须进行更改
gem 'mysql2'
并运行bundle install
。
参考:以下是如何将mysql数据库连接到我们的rails应用程序的非常明确的解释。