0

I have a remote Mysql server, and got all privileges remotely. Here is the output of "show grants" after I logged in remotely, from local computer:

+-------------------------------------------------------------------------------------------------------------+
| Grants for user@%                                                                                            |
+-------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'mysqluser'@'%' IDENTIFIED BY PASSWORD '*B25E737EE2274D7343BF9DCDF6CAF8DB2EAC17E1' |
+-------------------------------------------------------------------------------------------------------------+

However, when I try to use this server in a local rails environment, it says this:

/home/myuser/.rvm/gems/ruby-1.9.3-p429@my_project/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:in connect': Access denied for user 'mysqluser'@'localhost' (using password: YES) (Mysql2::Error) from /home/myuser/.rvm/gems/ruby-1.9.3-p429@my_project/gems/mysql2-0.3.11/lib/mysql2/client.rb:44:ininitialize'

Here is my database.yml:

development:
  adapter: mysql2
  encoding: utf8
  reconnect: true
  username: mysqluser
  password: password
  hostname: 192.10.23.114
  database: db_name
  pool: 5
  timeout: 5000

What I don't understand is why Mysql thinks my user is from "localhost" when I was actually using a remote access? Do you guys have any idea on this? Thanks a lot.

tuo
  • 586
  • 1
  • 4
  • 20

2 Answers2

2

Use of hostname is incorrect.

It should read:

host: 192.10.23.114

sren
  • 3,513
  • 4
  • 25
  • 28
  • 1
    I had originally posted the same answer, but I believe it's incorrect. The `mysql2` gem's client adapter doesn't care if you pass a `:host` or `:hostname` option. https://github.com/brianmario/mysql2/blob/master/lib/mysql2/client.rb#L51 – deefour Jun 17 '13 at 06:10
  • I tried Simon's solution and it worked! As Deefour said, I thought mysql2 accepts :host and :hostname equally, but it turns out it doesn't. Any ip address after :hostname is ignored and mysql2 uses "localhost" instead. – tuo Jun 17 '13 at 06:45
  • 1
    Deefour, I got the reason now. lastest tag of Mysql2 is 0.3.11 which is what I'm using. In this version the client.rb is like this: https://github.com/brianmario/mysql2/blob/f41050ea8bd4e546369e702fb7853e05b6635954/lib/mysql2/client.rb – tuo Jun 17 '13 at 07:10
0

Tuo,

Additionally, you're going to want to make sure you have the mysql2 gem installed. For more configuration details, please check: http://guides.rubyonrails.org/getting_started.html#configuring-a-database

meoww-
  • 1,892
  • 2
  • 21
  • 29
  • thanks meoww-. I have mysql2 gem installed. In fact if I don't have mysql2, it won't give me an error. :) – tuo Jun 17 '13 at 06:46