Reputation: 595
I have two amazon ec2 instances. One I am using as a webserver and the other one has the mysql DB. I have the below php script that I run from the web Server. I cant seem to connect to my Database. When I run the php script on the mysql server with $host= localhost, it works. How can I access the mysql server?
<?php
$host="ipaddress"; // Host name
$username="root"; // Mysql username
$password="mypassword"; // Mysql password
$db_name="myDB"; // Database name
$port=3306;
// Create connection
$conn = new mysqli($host, $username, $password, $db_name,$port);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}else
{
echo "Connected";
}
?>
Upvotes: 1
Views: 2004
Reputation: 24959
Have the user/host combo as a legitimate user in mysql.user
select user,host from mysql.user;
Have the aws ec2 security group open (the aws Firewall)
There are three choices here: my IP, custom, or anywhere for the ip addr CIDR
This is the bind-address and skip-networking setup. See the nixcraft document for those few changes if needed.
Upvotes: 2