Can't Connect to remote Mysql server in Rails, but I can connect to it with command line client

StackOverflow https://stackoverflow.com/questions/17140453

  •  31-05-2022
  •  | 
  •  

Question

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.

Was it helpful?

Solution

Use of hostname is incorrect.

It should read:

host: 192.10.23.114

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top