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.

2 Answers 2

2

Use of hostname is incorrect.

It should read:

host: 192.10.23.114

Sign up to request clarification or add additional context in comments.

3 Comments

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. github.com/brianmario/mysql2/blob/master/lib/mysql2/…
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.
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: github.com/brianmario/mysql2/blob/…
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

1 Comment

thanks meoww-. I have mysql2 gem installed. In fact if I don't have mysql2, it won't give me an error. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.