# Could not connect to an external database

**URL:** <https://discourse.cakephp.org/t/could-not-connect-to-an-external-database/4238>\
**Category:** Need Help\
**Created:** [April 30, 2018, 4:29pm UTC](https://discourse.cakephp.org/t/could-not-connect-to-an-external-database/4238 "2018-04-30T16:29:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ingabriel](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ingabriel/32/1012_2.png) [@Ingabriel](https://discourse.cakephp.org/u/Ingabriel)\
**Post date:** [April 30, 2018, 4:29pm UTC](https://discourse.cakephp.org/t/could-not-connect-to-an-external-database/4238/1 "2018-04-30T16:29:00Z")

</div>

Hi:

Although i have configured an external database connection the same way i used to with cakePhp 2, it wasn’t possible to connect using the cakePhp 3.6. It keeps showing me the same error message:

_CakePHP is NOT able to connect to the database._  
_Connection to database could not be established: SQLSTATE[HY000] [1045] Access denied for user ‘surfgurusql’@‘localhost’ (using password: YES)_

The configuration in Config/app.php , however, is NOT pointing to localhost:

```
'Datasources' => [

    'surfguru' => [
        'className' => 'Cake\Database\Connection',
        'driver' => 'Cake\Database\Driver\Mysql',
        'persistent' => false,
        'host' => '#########.rds.amazonaws.com',
        'port' => '3306',
        'username' => 'surfgurusql',
        'password' => '########',
        'database' => ' *****',
        'unix_socket' => '/opt/bitnami/mysql/tmp/mysql.sock',
        'encoding' => 'utf8',
        'timezone' => 'UTC',
        'flags' => [],
        'cacheMetadata' => false,
        'log' => true,
        'quoteIdentifiers' => false,
        'url' => env('###########.rds.amazonaws.com', null)
    ]

],

```

Does someone knows the answer?

Thanks,  
Gabriel

---

<div class="post-metadata">

**Author:** ![jarekgol](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@jarekgol](https://discourse.cakephp.org/u/jarekgol)\
**Post date:** [May 2, 2018, 6:36am UTC](https://discourse.cakephp.org/t/could-not-connect-to-an-external-database/4238/2 "2018-05-02T06:36:07Z")

</div>

Maybe try remove `unix_socket` ?

Also check if you enabled “external” user in your database.

---

<div class="post-metadata">

**Author:** ![Ingabriel](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ingabriel/32/1012_2.png) [@Ingabriel](https://discourse.cakephp.org/u/Ingabriel)\
**Post date:** [May 2, 2018, 9:12pm UTC](https://discourse.cakephp.org/t/could-not-connect-to-an-external-database/4238/3 "2018-05-02T21:12:09Z")

</div>

Perfect!

It was the “unix\_socket” variable!

As i told, i was already using the same database server with an old version of cakePhp, said that, there was no problem with the database server itself.

Thank you very much for the answer Jarekgol !

---

<div class="post-metadata">

**Author:** ![Ingabriel](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ingabriel/32/1012_2.png) [@Ingabriel](https://discourse.cakephp.org/u/Ingabriel)\
**Post date:** [May 2, 2018, 9:14pm UTC](https://discourse.cakephp.org/t/could-not-connect-to-an-external-database/4238/4 "2018-05-02T21:14:38Z")

</div>

The correct form, that WORKS! is below:

> [@Ingabriel](#):
>
> ‘Datasources’ =\> [
> 
> ```
> 'surfguru' => [
> 'className' => 'Cake\Database\Connection',
> 'driver' => 'Cake\Database\Driver\Mysql',
> 'persistent' =>false,
> 'host' => '#########.rds.amazonaws.com',
> 'port' => '3306',
> 'username' => 'surfgurusql',
> 'password' => '########',
> 'database' => ' *****',
> 'encoding' => 'utf8',
> 'timezone' => 'UTC',
> 'flags' => [],
> 'cacheMetadata' => false,
> 'log' => true,
> 'quoteIdentifiers' => false,
> 'url' => env('###########.rds.amazonaws.com', null)
> ]
> 
> ```
> 
> ],
