# Can't connect to database

**URL:** https://community.kinsta.com/t/cant-connect-to-database/1061
**Category:** Application Support
**Created:** [October 24, 2021, 8:10am UTC](https://community.kinsta.com/t/cant-connect-to-database/1061 "2021-10-24T08:10:07Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![jromero\_arro](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@jromero\_arro](https://community.kinsta.com/u/jromero_arro)
#### Post date: [January 8, 2022, 3:09pm UTC](https://community.kinsta.com/t/cant-connect-to-database/1061/4 "2022-01-08T15:09:50Z")

</div>

I ran into a similar issue although not sure the solution would be exactly the same for your case.

**TLDR; The database configuration for `root` out-of-the-box is wrong…**

_(This is a really bad first expirience with getting DevKinsta setup)_

### Verify

To verify this I did the following:

```auto
# access the database container
docker exec -it devkinsta_db bash

# in the container, try to login provided credentials
mysql -p

```

The result was:

```auto
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

```

### Resolve

The resolution was to set the `root` password using `mysqladmin`:

```auto
# access the database container
docker exec -it devkinsta_db bash

# set root password (use password provided in DevKinsta UI)
mysqladmin -u root password

# verify you can now access the database
mysql -p

# print the databases (optional)
show databases;

```

**EDIT: I ran into further issues with the database configuration out-of-the-box.**

The database user access is limited to `localhost` but because of how the infrastructure/network is setup that means that no other service can access it. When it creates the website it says it was successful but then you run into a few issues:

- WordPress - “Error establishing a database connection”
- Adminer - “SQLSTATE[HY000] [2006] MySQL server has gone away”

### Resolve

To resolve this you need to grant access from other hosts (in this case they are containers). None the less it’s fairly straightforward:

```auto
# access the database container
docker exec -it devkinsta_db bash

# login to mysql
mysql -p

# show access
show grants for 'root'@'localhost';

# copy the one that starts with "GRANT ALL PRIVILEGES" replace `root`@`localhost` with `root`@`%`
GRANT ALL PRIVILEGES ON *.* TO `root`@`%` IDENTIFIED BY PASSWORD '{ENCODED_PASSWORD}' WITH GRANT OPTION;

```

Now simply click “Retry” in the UI and it should get pass the error.

---

_[View the full topic](https://community.kinsta.com/t/cant-connect-to-database/1061)._
