0

I have hosted a site in AWS. I have created a RDS DB instance for the elastic beanstalk. In my laravel app's config/database.php file, I have configured my database connection as :

'mysql' => [
         'driver' => 'mysql',
         'host' => 'mydbidentefier.cdh7pykyg7in.ap-south-1.rds.amazonaws.com',
         'port' => 3306,
         'database' => 'mydbidentefier',
         'username' => 'admin',
         'password' => 'mypw',
         'unix_socket' => env('DB_SOCKET', ''),
         'charset' => 'utf8mb4',
         'collation' => 'utf8mb4_unicode_ci',
         'prefix' => '',
         'strict' => true,
         'engine' => null,
     ],

Now when I try to run php artisan migrate by SSHing into the EC2 instance, I get this error :

SQLSTATE[HY000] [1049] Unknown database 'mydbindentifier' (SQL: select * from projects)

The "mydbidentifier" is the DB identifier that is shown in the RDS console. How can that not be found.

One more thing : Should I not be able to run mysql from the command line by SSHing into the EC2 instance ? When I try mysql -u root -p by SSHing into the EC2 command line terminal. I get another error :

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Am I missing anything? Any guidance would be highly appreciated.

  • `mysql -u root -p`won't work like that because MySQL is running on the RDS instance and not the ec2 instance. You need to set the RDS endpoint as a parameter there. You probably have an error in your route table. Get MySQL from ec2 to RDS running to confirm that routing isn't the problem. – Henrik Pingel Jul 15 '20 at 07:17
  • I got it working with mysql -u root -p -h mydbidentefier.cdh7pykyg7in.ap-south-1.rds.amazonaws.com – Sijan Bhattarai Jul 15 '20 at 08:08
  • Are you sure the database is initialized? https://serverfault.com/questions/939488/unknown-database-when-trying-to-connect-to-an-aws-rds-instance – Henrik Pingel Jul 15 '20 at 08:11
  • I figured that 'mydbidentifier' was not the database name as I was using it, it was rather the DB instance identifier, I user 'ebdb' as DB name and it is working fine now. Thanks for the help. – Sijan Bhattarai Jul 15 '20 at 08:16

0 Answers0