0

I am trying to connect a laravel application to a remote database.The connection works successfully on my local machine but does not work in the production environment.The laravel application is connected to its own database hosted in the cloud but i want to access another database hosted by another provider.Hence,I did the following:

  1. In Config/database file in laravel folder,I added another mysql connection

  2. config the .env file as well.

             'mysql' => [
             'driver' => 'mysql',
             'host' => env('DB_HOST', '127.0.0.1'),
             'port' => env('DB_PORT', '3306'),
             'database' => env('DB_DATABASE', 'forge'),
             'username' => env('DB_USERNAME', 'forge'),
             'password' => env('DB_PASSWORD', ''),
             'unix_socket' => env('DB_SOCKET', ''),
             'charset' => 'utf8mb4',
             'collation' => 'utf8mb4_unicode_ci',
             'prefix' => '',
             'strict' => false,
             'engine' => null,
         ],
             'mysql3' => [
             'driver'    => 'mysql',
             'host'      => env('DB_HOST_THIRD','localhost'),
             'port'      => env('DB_PORT_THIRD'),
             'database'  => env('DB_DATABASE_THIRD',''),
             'username'  => env('DB_USERNAME_THIRD',''),
             'password'  => env('DB_PASSWORD_THIRD',''),
         ],
    

Then in .env file:

DB_CONNECTION=mysql3
DB_HOST_THIRD=remote IP
DB_PORT_THIRD=3306
DB_DATABASE_THIRD=Remote DB Name
DB_USERNAME_THIRD=Username
DB_PASSWORD_THIRD=password

With the above setting, i can connect to the remote database successfully on my local machine. Upon deployment, I am unable to connect to this remote database,even though a designated user has been created and access granted through the control panel.This remote database is hosted by GoDaddy and i have called but they said nothing is blocking my application, that everything is ok from their end. Below are what I have done:

  1. I am able to connect the remote Database using Sqlyog, Mysql client successfully.
  2. I connected to Terminal on the Remote Cpanel and try to grant all access to the User at its IP but the response is: "Access denied for user 'username@Remote IP'(using password:YES)".

From web application, the error is : "SQLSTATE[HY000] [2002] Connection refused". I have telnet the remote IP with port 3306, which respond well. Please, can someone help me, perhaps there are things i am missing or is this kind of issue peculiar to Godaddy shared hosting?. I have checked the following from Stackoverflow:

Enable remote MySQL connection: ERROR 1045 (28000): Access denied for user

David Mukoro
  • 467
  • 1
  • 8
  • 25
  • Make sure the user in your mysql database is capitalized `Username`, I highly recommend using uncapitalized words. – Ali Arabat Jan 18 '22 at 14:09
  • @AliArabat: Do you mean the Username itself? Be more precise – David Mukoro Jan 18 '22 at 15:15
  • Of course I do mean the Uername Itself – Ali Arabat Jan 18 '22 at 19:16
  • @AliArabat: the same issue persists even after changing the username as instructed. But I got another information that because it is shared hosting, I cannot connect a third party application to the one hosted by GoDaddy. Could this be true? – David Mukoro Jan 19 '22 at 10:34

0 Answers0