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 6806177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:40:42+00:00 2026-05-26T19:40:42+00:00

I have created three EC2 instances, two of instances are web servers and one

  • 0

I have created three EC2 instances, two of instances are web servers and one instance is a MySQL server. I would like to connect to the MySQL server and retrieve data. I was wondering how I can send a SQL query to the MySQL server.

<?php

$server = "localhost";
$username = "username";
$password = "password";
$database_name = "dbname";

$dbconnect = mysql_connect($server, $username, $password);

if(!$dbconnect)
{
    //connection failed to the host
    echo "-1";
    exit;
}

if(!mysql_select_db($database_name))
{
    //cannot connect to database
    echo "-2";
    exit;
}

?>

I used this php script to connect to the local mysql server. If I want to connect to the remote MySQL server on EC2 instance then do I just simply replace the server address to the IP address (elastic IP address) of the EC2 instance that running MySQL server?

  • 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-05-26T19:40:43+00:00Added an answer on May 26, 2026 at 7:40 pm

    Instead of using the Elastic IP address, use the DNS name associated with the Elastic IP address. It will resolve to the internal IP address associated with the current instance mapped to the Elastic IP address. This saves you in latency and cost.

    Here’s an article I wrote that describes this approach:

    Using Elastic IP to Identify Internal Instances on Amazon EC2
    http://alestic.com/2009/06/ec2-elastic-ip-internal

    You’ll also need to make sure that your MySQL database is listening on 0.0.0.0 instead of 127.0.0.1. Check that your MySQL database server is not accessible from the Internet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have few servers running on Amazon's EC2 and I would like to backup
I have created a javascript object var spanglist = { one: q1, two:q2, three:q3,
i have created three linear layouts of equal weights. Inside one of the linear
i am new to iPad developer, i have created two or three iPad application
i have one problem with handling list,i have three class named as UserInf,userData,userProcess,i created
I have created a div there are two childs of that div one is
I have created a small game in Java and I would like to add
I have created three checkbox controls for three threads and each would start by
i am new to iPad developer, i have created two or three iPad application
i am new to iPad developer, i have created two or three iPad application

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.