Lance
Lance

Reputation: 4820

Remotely connect to MySQL database that's hosted on AWS

I recently installed a LAMP stack on an ec2 instance that's running Ubuntu Linux. I followed the instructions found here. I also installed phpmyadmin. To the best of my knowledge, while I was installing MySQL, I answered no when prompted to answer the question Disallow root login remotely? I could be mistaken though. I've read elsewhere that in order to allow root login remotely, I would need to edit the mysql .conf file found in the /etc folder somewhere and edit the bridge setting.

I've tried connecting by doing the following:

$con = mysqli_connect('ec-2 ip address', 'root', 'root', 'db_name');

if(mysqli_connect_errno($con)) {
    echo mysqli_connect_error($con);
    die;
}

This is the error message I get when I connect:

Can't connect to MySQL server on '54.201.165.105' (61) 

Upvotes: 1

Views: 3065

Answers (2)

Lance
Lance

Reputation: 4820

I ended up answering this myself after just doing a little bit of research. Turns out that the security groups pn AWS had nothing to do with the problem. I had to go to the file at /etc/mysql/my.cnf and comment out the line that read bind_address = 127.0.0.1. Then I had to execute an SQL statement in phpmyadmin that went like this

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

Thanks for all of the help though, guys. I appreciate it.

Upvotes: 3

Spechal
Spechal

Reputation: 2706

You need modify the AWS Security Group for the instance and set firewall rules to allow 3306 inbound traffic as well as modify the OS firewall rules to allow the same traffic.

Upvotes: 1

Related Questions