# Could not connect to database, check logs/librenms.log. Need some help

**URL:** <https://forums.jasonloong.com/t/could-not-connect-to-database-check-logs-librenms-log-need-some-help/55>\
**Category:** Website Posts\
**Tags:** tutorials\
**Created:** [April 7, 2023, 8:58pm UTC](https://forums.jasonloong.com/t/could-not-connect-to-database-check-logs-librenms-log-need-some-help/55 "2023-04-07T20:58:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Korvo](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/korvo/32/72_2.png) [@Korvo](https://forums.jasonloong.com/u/Korvo)\
**Post date:** [April 7, 2023, 8:58pm UTC](https://forums.jasonloong.com/t/could-not-connect-to-database-check-logs-librenms-log-need-some-help/55/1 "2023-04-07T20:58:33Z")

</div>

Hi everyone,

I have some trouble getting LibreNMS and mariadb to work on Synology Docker following this tutorial:  
[Synology SNMP Network Monitoring with LibreNMS Docker - Jason Loong | Tech Enthusiast, Photographer & Drummer](https://jasonloong.com/blog/synology-snmp-network-monitoring-with-librenms-docker/1)

At the moment I get to setup: **`docker exec librenms setup_database`** I receive an error message:

> Could not connect to database, check logs/librenms.log

This is the librenms log file:

> [2023-04-07T20:07:35.154979+02:00] local.ERROR: PDOException: SQLSTATE[HY000] [1045] Access denied for user ‘librenms’@‘172.17.0.13’ (using password: YES) in /opt/librenms/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:40  
> Stack trace:  
> [2023-04-07T22:37:47.122224+02:00] production.ERROR: PDOException: SQLSTATE[HY000] [1045] Access denied for user ‘librenms’@‘172.17.0.13’ (using password: YES) in /opt/librenms/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:40  
> Stack trace:  
> #0 /opt/librenms/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(40): PDO-\>\_\_construct()  
> #1 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(67): Doctrine\DBAL\Driver\PDOConnection-\>\_\_construct()  
> #2 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(46): Illuminate\Database\Connectors\Connector-\>createPdoConnection()  
> #3 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php(24): Illuminate\Database\Connectors\Connector-\>createConnection()  
> #4 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connectors/ConnectionFactory.php(184): Illuminate\Database\Connectors\MySqlConnector-\>connect()  
> #5 [internal function]: Illuminate\Database\Connectors\ConnectionFactory-\>Illuminate\Database\Connectors{closure}()  
> #6 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php(1064): call\_user\_func()  
> #7 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php(1100): Illuminate\Database\Connection-\>getPdo()  
> #8 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php(442): Illuminate\Database\Connection-\>getReadPdo()  
> #9 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php(368): Illuminate\Database\Connection-\>getPdoForSelect()  
> #10 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php(705): Illuminate\Database\Connection-\>Illuminate\Database{closure}()  
> #11 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php(672): Illuminate\Database\Connection-\>runQueryCallback()  
> #12 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php(376): Illuminate\Database\Connection-\>run()  
> #13 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2414): Illuminate\Database\Connection-\>select()  
> #14 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2402): Illuminate\Database\Query\Builder-\>runSelect()  
> #15 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2936): Illuminate\Database\Query\Builder-\>Illuminate\Database\Query{closure}()  
> #16 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2403): Illuminate\Database\Query\Builder-\>onceWithColumns()  
> #17 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(625): Illuminate\Database\Query\Builder-\>get()  
> #18 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(609): Illuminate\Database\Eloquent\Builder-\>getModels()  
> #19 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(294): Illuminate\Database\Eloquent\Builder-\>get()  
> #20 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(474): Illuminate\Database\Eloquent\Builder-\>first()  
> #21 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(508): Illuminate\Database\Eloquent\Builder-\>firstOrNew()  
> #22 /opt/librenms/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php(23): Illuminate\Database\Eloquent\Builder-\>updateOrCreate()  
> #23 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2132): Illuminate\Database\Eloquent\Model-\>forwardCallTo()  
> #24 /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2144): Illuminate\Database\Eloquent\Model-\>\_\_call()  
> #25 /opt/librenms/LibreNMS/Config.php(262): Illuminate\Database\Eloquent\Model::\_\_callStatic()  
> #26 /opt/librenms/LibreNMS/Config.php(460): LibreNMS\Config::persist()  
> #27 /opt/librenms/LibreNMS/Config.php(61): LibreNMS\Config::processConfig()  
> #28 /opt/librenms/app/Providers/ConfigServiceProvider.php(27): LibreNMS\Config::load()  
> #29 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\Providers\ConfigServiceProvider-\>boot()  
> #30 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container{closure}()  
> #31 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()  
> #32 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()  
> #33 /opt/librenms/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\Container\BoundMethod::call()  
> #34 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(924): Illuminate\Container\Container-\>call()  
> #35 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(905): Illuminate\Foundation\Application-\>bootProvider()  
> #36 [internal function]: Illuminate\Foundation\Application-\>Illuminate\Foundation{closure}()  
> #37 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(906): array\_walk()  
> #38 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\Foundation\Application-\>boot()  
> #39 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(237): Illuminate\Foundation\Bootstrap\BootProviders-\>bootstrap()  
> #40 /opt/librenms/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(310): Illuminate\Foundation\Application-\>bootstrapWith()  
> #41 /opt/librenms/LibreNMS/Util/Laravel.php(44): Illuminate\Foundation\Console\Kernel-\>bootstrap()  
> #42 /opt/librenms/includes/init.php(88): LibreNMS\Util\Laravel::bootCli()  
> #43 /opt/librenms/includes/sql-schema/update.php(30): require(‘…’)  
> #44 {main}

My mariadb container is on IP **172.17.0.12**  
My LibreNMS container IP **172.17.0.13**  
My Synology NAS IP **192.168.1.202**

I don’t use the firewall on the Synology NAS.

> This is the mariadb docker setup I use:  
> docker run -d --name=mariadb   
> -p 3306:3306   
> -e PUID=1027   
> -e PGID=100   
> -e TZ=Europe/Brussels   
> -e MYSQL\_ROOT\_PASSWORD=SomeSecretPassword   
> -v /volume1/docker/mariadb:/etc/mysql/conf.d   
> –sql-mode=’’  
> –restart always   
> mariadb:latest

Using this two additional line give errors:

```auto
--innodb_file_per_table=1 \
--lower_case_table_names=0 \

```

I guess these enviroment settings schould defined as **‘-e’** be but not tested yet:

```auto
-e innodb_file_per_table=1 \
-e lower_case_table_names=0 \

```

This is my LibreNMS Docket setting:

> docker run -d --name librenms   
> -p 8668:80   
> -e DB\_HOST=libredb   
> -e DB\_NAME=librenms   
> -e DB\_USER=librenms   
> -e DB\_PASS=SomeSecretPassword   
> -e APP\_KEY=base64: PUT YOUR GENERATED APP KEY HERE   
> -e BASE\_URL=[http://192.168.1.202:8668](http://192.168.1.202:8668)   
> -e TZ=Europe/Brussels   
> –link mariadb:libredb   
> -v /volume1/docker/librenms/logs:/opt/librenms/logs   
> -v /volume1/docker/librenms/rrd:/opt/librenms/rrd   
> -v /volume1/docker/librenms/custom.config.php:/opt/librenms/conf.d/custom.config.php:ro   
> –restart always   
> jarischaefer/docker-librenms:latest

Any further advice is welcome.

---

<div class="post-metadata">

**Author:** ![jasonloong](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/jasonloong/32/8_2.png) [@jasonloong](https://forums.jasonloong.com/u/jasonloong)\
**Post date:** [April 7, 2023, 10:43pm UTC](https://forums.jasonloong.com/t/could-not-connect-to-database-check-logs-librenms-log-need-some-help/55/2 "2023-04-07T22:43:46Z")

</div>

Hi @Korvo

Thank you for the logs

> [@Korvo](#):
>
> ```auto
> [2023-04-07T20:07:35.154979+02:00] local.ERROR: PDOException: SQLSTATE[HY000] [1045] Access denied for user ‘librenms’@‘172.17.0.13’ (using password: YES) in /opt/librenms/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:40
> Stack trace:
> [2023-04-07T22:37:47.122224+02:00] production.ERROR: PDOException: SQLSTATE[HY000] [1045] Access denied for user ‘librenms’@‘172.17.0.13’ (using password: YES) in /opt/librenms/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:40
> 
> ```

It seems like a permissions issue

1. Can you confirm that you have setup the sql user “librenms” with the correct permissions? (Replace libre\_password with your\_password)

```auto
CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE USER 'librenms'@'%' IDENTIFIED BY 'libre_password';
CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'libre_password';
GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'%';
FLUSH PRIVILEGES;
exit

```

1. Your MariaDB container volume mount has no persistent storage , volume is linked to the sql conf.d ~ unless you’ve setup the permissions above in the confd, the sql container starts from “fresh” whenever you restart the container

---

<div class="post-metadata">

**Author:** ![Korvo](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/korvo/32/72_2.png) [@Korvo](https://forums.jasonloong.com/u/Korvo)\
**Post date:** [April 8, 2023, 12:47am UTC](https://forums.jasonloong.com/t/could-not-connect-to-database-check-logs-librenms-log-need-some-help/55/3 "2023-04-08T00:47:58Z")

</div>

1. I can confirm that I have put the passwords at ‘libre\_password’
2. Yes you are right, this is my mistake and have changed it to:  
**-v /volume1/docker/mariadb:/var/lib/mysql** \

However I got the same results when using the command:  
`docker exec librenms setup_database`

CLI output:  
`Could not connect to database, check logs/librenms.log`

I also noticed my PUID and PGID are not correct.  
Command ‘ID’ shows this:

```auto
root@DiskStation:~# id
uid=0(root) gid=0(root) groups=0(root),2(daemon),19(log)

```

So I have to set it this way or am I mistaken?

> -e PUID=0   
> -e PGID=0 \

Mabe also goot to mention I’m running **DSM 7.1.1**  
Synology Docker version **20.10.3-1308**

Any idea ?

---

<div class="post-metadata">

**Author:** ![jasonloong](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/jasonloong/32/8_2.png) [@jasonloong](https://forums.jasonloong.com/u/jasonloong)\
**Post date:** [April 8, 2023, 1:55am UTC](https://forums.jasonloong.com/t/could-not-connect-to-database-check-logs-librenms-log-need-some-help/55/4 "2023-04-08T01:55:24Z")

</div>

Thanks for the reply @Korvo

Are the logs showing the same permission errors? with the new MariaDB container?

I would suggest just copy/paste the commands on my tutorial before changing passwords etc, just to test/make sure the commands work

1. start from beginning, remove both librenms and mariadb containers just in case they have any existing configs written when you attempted the tutorial
2. Note on MariaDB container setup, you will probably encounter 2002 error, wait for awhile, and run `docker exec -it mariadb mysql -u root -p`

```auto
docker stop librenms && docker rm librenms
docker stop mariadb && docker rm mariadb
cd /volume1/docker
rm -r mariadb
rm -r librenms

```

### PUID/GUID

> [@Korvo](#):
>
> -e PUID=0  
> -e PGID=0 \

Do not have to set this, Synology runs Docker as `root`, just let the MariaDB container handle the permissions

### Test run on my end

Everything works, i copy and paste the commands into my Syno as per the tutorial 😁  
Version: `DSM 7.1.1-42962 Update 4`

 ![Screenshot 2023-04-08 at 9.41.14 AM](https://forums.jasonloong.com/uploads/default/original/1X/471045d547a8d4c82c90f9f4fabf38aa83542314.png)

Let me know again if it fails~

---

<div class="post-metadata">

**Author:** ![Korvo](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/korvo/32/72_2.png) [@Korvo](https://forums.jasonloong.com/u/Korvo)\
**Post date:** [April 9, 2023, 7:59pm UTC](https://forums.jasonloong.com/t/could-not-connect-to-database-check-logs-librenms-log-need-some-help/55/5 "2023-04-09T19:59:38Z")

</div>

Today I have copy and paste from your website and it works !!! THANKS !!!

However now I still don’t understand what went wrong in the first place 😕

On thing I should mention about is the mariadb setting option that is required by LibreNMS: [Installing LibreNMS - LibreNMS Docs](https://docs.librenms.org/Installation/Install-LibreNMS/#set-timezone)

If I understand correctly they should be:

```auto
-e innodb_file_per_table=1 \
-e lower_case_table_names=0 \

```

instead of:

```auto
-- innodb_file_per_table=1 \
-- lower_case_table_names=0 \

```

Please correct me if I’m wrong.

---

<div class="post-metadata">

**Author:** ![jasonloong](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/jasonloong/32/8_2.png) [@jasonloong](https://forums.jasonloong.com/u/jasonloong)\
**Post date:** [April 10, 2023, 10:20am UTC](https://forums.jasonloong.com/t/could-not-connect-to-database-check-logs-librenms-log-need-some-help/55/6 "2023-04-10T10:20:52Z")

</div>

Thanks for reporting in! Glad it works

> [@Korvo](#):
>
> However now I still don’t understand what went wrong in the first place 😕

I assume the first mistake was mounting the wrong volume, when MariaDB starts, it will “prepare” files, so somewhere, the permissions didn’t save, and when you issued the `docker restart mariadb` , the database did not have persistent storage, so it restarted into a “fresh” container (thus the permission errors, `librenms` does not exist)

### Restart

If you still have time, you might want to revisit the copy/paste commands? Like change to your password, and timezone (you will need to clear the containers again though, as listed above)

> [@jasonloong](#):
>
> ```auto
> docker stop librenms && docker rm librenms
> docker stop mariadb && docker rm mariadb
> cd /volume1/docker
> rm -r mariadb
> rm -r librenms
> 
> ```

> [@Korvo](#):
>
> If I understand correctly they should be:
> 
> ```auto
> -e innodb_file_per_table=1 \
> -e lower_case_table_names=0 \
> 
> ```

The official docs saves the runtime config in a file, if we do -e in docker, it means it’s a environment variable in Linux. MariaDB docker do not read the environment variable above, so you would be starting mariadb without those arguments

Because it’s a docker container, they have a few environment variables you can set via the container, but not the above. You can see the EV they allow on the MariaDB docker page

[Docker MariaDB](https://hub.docker.com/_/mariadb)

> [@Korvo](#):
>
> ```auto
> -- innodb_file_per_table=1 \
> -- lower_case_table_names=0 \
> 
> ```

Because the Container EV does not include innodb\_file\_per\_table , etc etc, the tutorial run them as arguments when MariaDB starts up in the container

[MariaDB docker build tag @ latest](https://hub.docker.com/layers/library/mariadb/latest/images/sha256-7781ab82c8701e38b7a039ca155beca4574bd36ac19e5f54b99cee9666ac2249?context=explore)

see last line of `23 CMD ["mariadbd"]`

The double `--` , are the arguments when starting MariaDB. The MariaDB container already runs `mariadbd` default, so putting these two arguments will result in `mariadbd --argument1 --argument2`

### Tutorial should be easy

As a tutorial, I made things simple so that its easy to copy/paste, you can definitely make your own MariaDB config file, and then point the Docker container to read the config file for MariaDB container

```auto
docker run --name some-mariadb -v /my/custom:/etc/mysql/conf.d --rm mariadb:latest my_print_defaults --mysqld

```

The -v  
`-v /my/custom:/etc/mysql/conf.d`

Inside /my/custom should be a `my_custom_config.cnf`, which should include the config for

```auto
# my_custom_config.cnf
# # check the proper config syntax to set these arguments
innodb_file_per_table=1
lower_case_table_names=0

```

so the tutorial docker run command will become:

```auto
docker run \
-v /volume1/docker/mariadb:/var/lib/mysql \ # the persistent storage
-v /my/custom:/etc/mysql/conf.d \ # the custom config folder
-e MYSQL_ROOT_PASSWORD='root_password' \
-e TZ=Asia/Singapore \
--name mariadb \
-d \
--restart always \
mariadb:latest

```

Hope that helps clear up some docker usage 😁

---

<div class="post-metadata">

**Author:** ![Korvo](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/korvo/32/72_2.png) [@Korvo](https://forums.jasonloong.com/u/Korvo)\
**Post date:** [April 10, 2023, 7:41pm UTC](https://forums.jasonloong.com/t/could-not-connect-to-database-check-logs-librenms-log-need-some-help/55/7 "2023-04-10T19:41:47Z")

</div>

Thank you Jason to clear these things up for me 👍  
Whish we both could grab a beer, soda or coffee together 😆

---

<div class="post-metadata">

**Author:** ![Korvo](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/korvo/32/72_2.png) [@Korvo](https://forums.jasonloong.com/u/Korvo)\
**Post date:** [April 10, 2023, 8:16pm UTC](https://forums.jasonloong.com/t/could-not-connect-to-database-check-logs-librenms-log-need-some-help/55/8 "2023-04-10T20:16:46Z")

</div>

And again I have a question 😏

Why do we have to create two users in mariadb ?

```auto
CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci;
>>>> CREATE USER 'librenms'@'%' IDENTIFIED BY 'libre_password';
>>>> CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'libre_password';
GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'%';
FLUSH PRIVILEGES;
exit

```

I this not enough ?

```auto
CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'your-password'

```

---

<div class="post-metadata">

**Author:** ![jasonloong](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/jasonloong/32/8_2.png) [@jasonloong](https://forums.jasonloong.com/u/jasonloong)\
**Post date:** [April 10, 2023, 11:54pm UTC](https://forums.jasonloong.com/t/could-not-connect-to-database-check-logs-librenms-log-need-some-help/55/9 "2023-04-10T23:54:32Z")

</div>

`localhost` in Docker context means only the container itself will have permissions to write to the DB

As the LibreNMS docs/installation expects you to install in a Linux instance, `localhost` makes sense as no one else should be able to access the DB from outside

Because we are using containers, you will need to add `%` so that any IP/network can have access to the container

For security hardening, you can set the container to only accept IP from another container for eg. `'librenms'@'172.17.0.3'`

---

<div class="post-metadata">

**Author:** ![Korvo](https://forums.jasonloong.com/user_avatar/forums.jasonloong.com/korvo/32/72_2.png) [@Korvo](https://forums.jasonloong.com/u/Korvo)\
**Post date:** [April 12, 2023, 4:52pm UTC](https://forums.jasonloong.com/t/could-not-connect-to-database-check-logs-librenms-log-need-some-help/55/10 "2023-04-12T16:52:06Z")

</div>

Thanks for the information.

It works now 👍
