简体   繁体   中英

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

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:in initialize'

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.

Use of hostname is incorrect.

It should read:

host: 192.10.23.114

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM