I've set up an EC2 instance it has mysql and php-mysql installed (not mysql-server).

I've set up an RDS instance and set the security group to the EC2 instance.

I can connect via the command line from the EC2, but when I try connecting via mysqli I get the message: Can't connect to MySQL server on 'XXXX.xxxxxxx.us-east-1.rds.amazonaws.com'

This is my first time working with both.

Am I missing something here?

define("HOST", "XXXX.xxxxxxx.us-east-1.rds.amazonaws.com");
define("DBUSER", "my_user");
define("PASS", "********");
define("DB", "mydb");
define("PORT", 3306);


// Check connection
if (mysqli_connect_errno($link)){
    echo "Failure to connect: " . mysqli_connect_error();

  • What is the complete command you are entering at the shell prompt?
    – jamieb
    Apr 1 '13 at 4:07
  • mysql -h XXXX.xxxxxxx.us-east-1.rds.amazonaws.com -P 3306 -u my_user -p Apr 1 '13 at 4:13
  • You're not specifying a database in that command. Are you sure it's the entire command?
    – jamieb
    Apr 1 '13 at 4:14
  • Yeah, it didn't connect to a specific DB but I WAS able to connect to the RDS server. However if I try the same via mysqli I'm getting "can't connect to server" Apr 1 '13 at 4:17
  • Try connecting with the database. Your user probably hasn't been given specific permission to access that database.
    – bahamat
    Apr 1 '13 at 6:22

I found a similar issue.

The solution was to run setsebool -P httpd_can_network_connect=1


I had to make changes for SELinux, my instance was RHEL6.

setsebool httpd_can_network_connect=1 setsebool httpd_can_network_connect_db on

What I found odd was that SELinux logged nothing unusual to /var/log/audit/audit.log


This helped me:

I removed the port specification in my DSN. Managed to connect form EC2 to RDS then.

Link: https://stackoverflow.com/questions/23955446/sqlstatehy000-2005-unknown-mysql-server-host-mysql1-alwaysdata-com3306-2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.