Search code examples
phpmysqllaravelamazon-web-servicesamazon-rds

Laravel cannot connect to MySQL in Amazon RDS, but can connect from command line


I am working on Laravel project hosted on AWS EC2(Ubuntu) with RDS(MySQL) on the same VPC. I can connect to MySQL through command line with no problem, but when Laravel app tries to connect to database, the access is denied.

SQLSTATE[HY000] [1045] Access denied for user 'username'@'ipaddress' (using password: Y ES) (SQL: select * from tablename)

Below is my DB config in .env file:

DB_HOST=verylonghostname.rds.amazonaws.com  
DB_PORT=3306 
DB_DATABASE=dbname   
DB_USERNAME=dbusername 
DB_PASSWORD=dbpassword

What might be the problem and how can I fix it?


Solution

  • I tried create another db user for laravel and it works! Apparently the connection is denied if I use db user name 'admin'. Perhaps it is one of security measure by AWS.