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:
Here is the error we get when running rake db:create:
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 /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.