Reputation: 1380
I am trying to access remote mysql database using rake task. Here i am posting my active record connection logic
client = ActiveRecord::Base.establish_connection(
:host => "server_ip",
:port => 22,
:adapter => "mysql2",
:pool => 5,
:database => "database_name",
:username => "username",
:password => "password"
)
I am accessing it using this
client.connection.execute("SELECT * FROM users")
But every time it results with error as given below
rake aborted!
Lost connection to MySQL server at 'reading initial communication packet', system error: 0
Is there anything i am missing. Please suggest me right direction
Upvotes: 3
Views: 4537
Reputation: 2793
Try the following,
Make sure MySQL connects from console with the same credentials
Make sure it connects in irb/rails console
If not, Add port number in the config you mentioned. MySQL should run in that port.
Check the access privilege for the username and IP in MySQL
Upvotes: 1