Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8757359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:16:57+00:00 2026-06-13T14:16:57+00:00

I am having trouble connecting to a MySQL DB on a remote server via

  • 0

I am having trouble connecting to a MySQL DB on a remote server via Ruby and the DBI gem.

For this example, the DB host’s address is 000.00.00.000, and the name of the DB is testdb.

Should username be my personal username I SSH into the server with or a specific MySQL username?
Should password be my personal password I SSH with or the MySQL password I use once I’m on?
Do I need to specify the port or anything else along with the IP address?

Here is the code I’m currently trying to use, which I found on this tutorial

require 'rubygems'
require 'mysql'
require 'dbi'

#connect to mysql database

begin
 # connect to the MySQL server
 dbh = DBI.connect("DBI:Mysql:testdb:000.00.00.000", 
                    "username", "password")
 # get server version string and display it
 row = dbh.select_one("SELECT VERSION()")
 puts "Server version: " + row[0]
rescue DBI::DatabaseError => e
 puts "An error occurred"
 puts "Error code:    #{e.err}"
 puts "Error message: #{e.errstr}"
ensure
 # disconnect from server
 dbh.disconnect if dbh
end

When I run:

Error code:    2003
Error message: Can't connect to MySQL server on  ... (60)

On SSH I am currently getting into MySQL with this command:

mysql -u root testdb -p

I have the password for this and that functions in my terminal.

What should I be putting in the DBI connect statement to connect correctly via Ruby?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:16:58+00:00Added an answer on June 13, 2026 at 2:16 pm

    Assuming that you run MySQL server on your local machine, try changing your connect line to:

    dbh = DBI.connect("DBI:Mysql:testdb:127.0.0.1",
         "root", "<rootmysqlpassword>")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble connecting to a remote mysql db with mysql2 gem. I get
I'm having trouble connecting to my mysql server with C# from a remote machine.
I am having trouble on connecting my C program to mysql. I've done most
I'm having trouble connecting to my local MySQL database from my PHP script. I
I am having trouble connecting my online application to others across another network. I
I'm using rubber to deploy a rails application and am having trouble connecting to
I'm doing my first C++ - Qt4 application and I'm having some trouble connecting
I'm having a bit of trouble connecting intstruments to my App on a iPod
I've having some trouble in connecting mvc 3 application in .net. I know that
I'm having trouble making a secondary MySQL connection (to a separate, external DB) in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.