连接到远程MySQL主机与Rails的问题 [英] Problems connecting to remote MySQL host with Rails

查看:276
本文介绍了连接到远程MySQL主机与Rails的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想连接到远程MySQL主机( rake db:create ),但Rails总是认为它是本地的。
使用以下配置的Database.yml:

I wanted to connect to a remote MySQL host (with rake db:create), but Rails always considers it to be local. Database.yml which uses the following config:

defaults: &defaults
  encoding: unicode
  adapter: mysql
  username: <username>
  password: *************
  port: 3306
  host: <remote ip address>

development:
  <<: *defaults
  database: <db name>
test: &test
  <<: *defaults
  database: <db name>
production:
  <<: *defaults
  database: <db name>

在数据库上尝试任何东西时总是出现这个错误:

And always get this error when trying anything on the database:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

配置只要使用本地数据库(即没有主机/端口部分)。
连接到远程MySQL服务器与给定的细节工作正常。

The config works as long as I use the local database (i.e. without the host/port part). Connecting to the remote MySQL server works fine with the given details.

有什么想法出错了?

编辑
问题只出现在 rake:db:create ,其他任务工作 - 错误消息

Edit: The problem only occurs with rake:db:create, other tasks work - The error message was really badly misleading.

推荐答案

您可能需要启用MySQL服务器接受远程请求(通过绑定到主机的IP地址或所有地址格式 0.0.0.0 )。编辑远程主机上的MySQL配置文件 my.cnf 。在Ubuntu中,您可以在 /etc/mysql/my.cnf

You may need to enable MySQL server to accept remote request (by binding to host's ip address or all address format 0.0.0.0). Edit MySQL configuration file my.cnf on the remote host. In Ubuntu, you can find the file in /etc/mysql/my.cnf

更改bind -address:

Change the value of bind-address:

bind-address            = 0.0.0.0

这篇关于连接到远程MySQL主机与Rails的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆