Can't connect Ruby on Rails to remote mysql database
Solution 1
I'm guessing that, per my original comment, your remote DB is refusing connections from anything but localhost. Based on that assumption, here are two solutions:
Use a ssh tunnel. There are tons of howto's for connecting over ssh tunnel, e.g., http://www.howtogeek.com/howto/ubuntu/access-your-mysql-server-remotely-over-ssh/.
Make sure your remote DB is accepting remote connections. Check out the accepted answer on the following stackoverflow thread Can't connect to MySQL server error 111
Solution 2
-
In your
my.cnf
, look for this line:bind-address = 127.0.0.1
and set address to
0.0.0.0
-
Access
mysql
:mysql -u root -p
-
Than create a user on
mysql
server and grant privileges to all:CREATE USER 'root'@'%' IDENTIFIED BY 'some_pass'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
Tony
Updated on June 04, 2022Comments
-
Tony almost 2 years
I'm trying to connect my rails 3 app to a mysql database hosted on a godaddy server. I am able to connect remotely using a mysql client, but not when I run the applicaton. I was able to connect on a local mysql, but when I try to connect to my remotely hosted database I get this error:
Mysql2::Error (Can't connect to MySQL server on '[host ip address]' (111))
Here is my database.yml
development: adapter: mysql2 encoding: utf8 host: host_ip_address port: 3306 database: database_name username: user_name password: password
I'm developing my application on an Ubuntu machine if that helps.
-
Tony over 12 yearsThanks alot the SSH tunnel connection worked. I had to enable ssh connections on my server, but it worked.