当前位置: 动力学知识库 > 问答 > 编程问答 >

Rails using localhost instead of remote ip host to connect to mysql2

问题描述:

When attempting to use a remote mysql database with rails, it ignores the host parameter in the database.yml file and attempts instead to connect to the local server name. I have sanitized the info below with XXX and localservername.

Below is the database.yml entry for development:

development:

adapter: mysql2

encoding: utf8

database: temp_admin_development

username: XXX

password: XXX

host: 10.X.X.X

port: 3306

Here is the error we get when running rake db:create:

rake aborted!

Mysql2::Error: Access denied for user 'XXX'@'localservername' to database 'temp_admin_development': CREATE DATABASE `temp_admin_development` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`

Here is a manual attempt to connect via irb:

Mysql2::Client.new(:host => "10.X.X.X", :username => "XXX")

Mysql2::Error: Access denied for user 'XXX'@'localservername' (using >password: NO)

from /home/XXX/.rvm/gems/ruby-1.9.3-p429/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `connect'

from /home/XXX/.rvm/gems/ruby-1.9.3-p429/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in `initialize'

from (irb):2:in `new'

from (irb):2

from /home/XXX/.rvm/rubies/ruby-1.9.3-p429/bin/irb:16:in `<main>'

Notice it is attempting to connect to the local server name and ignoring the host parameter being passed.

网友答案:

We found the issue. The host was actually being pulled in correctly. The problem was that we had to specify a database that already existed in mysql, not a new one. Once that was specified the rake db:migrate worked.

分享给朋友:
您可能感兴趣的文章:
随机阅读: