无法将Ruby on Rails连接到远程mysql数据库 [英] Can't connect Ruby on Rails to remote mysql database
问题描述
我正在尝试将Rails 3应用程序连接到Godaddy服务器上托管的mysql数据库.我可以使用mysql客户端进行远程连接,但无法在运行applicaton时进行连接.我能够在本地mysql上进行连接,但是当我尝试连接到远程托管数据库时,出现此错误:
I'm trying to connect my rails 3 app to a mysql database hosted on a godaddy server. I am able to connect remotely using a mysql client, but not when I run the applicaton. I was able to connect on a local mysql, but when I try to connect to my remotely hosted database I get this error:
Mysql2 :: Error(无法连接到"[主机IP地址]"上的MySQL服务器) (111))
Mysql2::Error (Can't connect to MySQL server on '[host ip address]' (111))
这是我的数据库.yml
Here is my database.yml
development:
adapter: mysql2
encoding: utf8
host: host_ip_address
port: 3306
database: database_name
username: user_name
password: password
如果有帮助,我正在Ubuntu机器上开发应用程序.
I'm developing my application on an Ubuntu machine if that helps.
推荐答案
根据我的原始评论,我猜测您的远程数据库正在拒绝除本地主机以外的任何连接.基于此假设,这里有两个解决方案:
I'm guessing that, per my original comment, your remote DB is refusing connections from anything but localhost. Based on that assumption, here are two solutions:
-
使用ssh隧道.有大量的howto通过ssh隧道进行连接,例如,确保您的远程数据库正在接受远程连接.在以下stackoverflow线程上查看接受的答案无法连接到MySQL服务器错误111
Make sure your remote DB is accepting remote connections. Check out the accepted answer on the following stackoverflow thread Can't connect to MySQL server error 111
这篇关于无法将Ruby on Rails连接到远程mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!