简体   繁体   English

无法使用Rails连接到远程MySQL数据库

[英]Can't connect to remote mysql db with rails

I'm having trouble connecting to a remote mysql db with mysql2 gem. 我无法使用mysql2 gem连接到远程mysql数据库。

I get this error: 我收到此错误:

Host 'my_ip' is not allowed to connect to this MySQL server

My db.yml says: 我的db.yml说:

remote_development:
  adapter: mysql2
  reconnect: false
  host: host_ip
  encoding: utf8
  database: host_db
  pool: 5
  username: root
  password:

And when I try to connect via my sql or telnet I have no problems at all. 当我尝试通过sql或telnet连接时,我一点都没有问题。 I've double and triple checked the data con my yml, but can't get through this. 我已经对yml数据进行了两次和三次检查,但是无法通过该检查。 Any idea? 任何想法?

Btw I'm using Rails 3.2.3, Ruby 1.9.3, and tried mysql2 v 0.2.18 and 0.3.11 ... pls HELP! 顺便说一句,我正在使用Rails 3.2.3,Ruby 1.9.3,并尝试了mysql2 v 0.2.18和0.3.11 ...请帮助!

I solved this, pretty simple... 我解决了这个问题,非常简单...

I just created a new user and password to the db with specific permissions instead of using root :) 我只是使用特定权限为数据库创建了一个新用户和密码,而不是使用root :)

Should have tried this from the beginning. 应该从一开始就尝试过。 I think this is the correct approach. 我认为这是正确的方法。

This seems to be a MySQL error message. 这似乎是MySQL错误消息。 I think the problem may be the user account that you are using. 我认为问题可能出在您使用的用户帐户。 It should be set up with the 'username'@'%' format when setting it up. 设置时,应使用'username'@'%'格式设置。 The percent sign means all ip addresses. 百分号表示所有IP地址。 You should then flush privileges on the server to make the account available. 然后,应flush privileges服务器上的flush privileges以使帐户可用。

development: 发展:

adapter: mysql2 适配器:mysql2

encoding: utf8 编码:utf8

reconnect: false 重新连接:错误

database: mystore_development 数据库:mystore_development

pool: 5 泳池:5

username: root 用户名:root

password:password 密码:password

host: localhost 主机:localhost

try this one surely it wil work... 一定可以尝试这个...

更改您的host:localhost然后再试一次,它将起作用

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

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