3

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.

5
  • have you tried messing with or asking GoDaddy about your socket setting? (/tmp/mysql.sock) Commented Dec 1, 2011 at 4:41
  • You wouldn't be using a socket to connect to a remote DB. @Tony, it looks most like the remote DB is refusing connections from anything by localhost. How did you connect to the remote db with the mysql client? Can you update your question with the command and response? One thing you could try to get over the hump is setup a ssh tunnel to the mysql host and connect through that. Commented Dec 1, 2011 at 13:36
  • @pduey I connected using mysql workbench with had no trouble, and I used the same host, port #, username, and password. I've never used ssh tunneling before; I'll do some research and try that out, and let you know if I get anywhere. Commented Dec 1, 2011 at 15:04
  • @gominimal I haven't resorted to speaking with GoDaddy support yet. I'm on a cheap cloud hosting plan, and my experience is whenever have an issue they tell me to upgrade to a more expensive dedicated hosting plan. Commented Dec 1, 2011 at 15:11
  • Correction to above comment (I guess you read it correctly anyway) - remote DB is refusing connections from anything but localhost. If you try connecting from the command line (or are you on windows?) you will get better diagnostics. Commented Dec 1, 2011 at 15:55

2 Answers 2

3

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:

  1. 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/.

  2. 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

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

1 Comment

Thanks alot the SSH tunnel connection worked. I had to enable ssh connections on my server, but it worked.
3
  • 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;
    

Comments

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.