SQLSTATE[HY000] [1045] Access denied for user 'librenms'@'localhost'

Hi LibreGurus!

My libreNMS setup stopped to work tonight.

I get database connection error but database is working fine.

librenms@sea0020sas18:~$ php validate.php
====================================
Component | Version
--------- | -------
LibreNMS  | 1.54-16-g01a519ef2
DB Schema | Not Connected (0)
PHP       | 7.2.19-0ubuntu0.18.04.1
MySQL     | ?
RRDTool   | 1.7.0
SNMP      | NET-SNMP 5.7.3
====================================

[OK]    Composer Version: 1.9.0
[OK]    Dependencies up-to-date.
Could not connect to database, check logs/librenms.log.

Here is log of troubleshooting.
https://p.libren.ms/view/404f9b83

I get this error message in my logs/librenms.log

> [2019-08-06 09:11:16] production.ERROR: SQLSTATE[HY000] [1045] Access denied for user 'librenms'@'localhost' (using password: YES) (SQL: selectuser_idfromuserswhere (auth_type= http-auth orauth_typeis null orauth_type= ) andusername= myusername limit 1) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 1045): SQLSTATE[HY000] [1045] Access denied for user 'librenms'@'localhost' (using password: YES) (SQL: selectuser_idfromuserswhere (auth_type= http-auth orauth_typeis null orauth_type= ) andusername= myusername limit 1) at /opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664, Doctrine\\DBAL\\Driver\\PDOException(code: 1045): SQLSTATE[HY000] [1045] Access denied for user 'librenms'@'localhost' (using password: YES) at /opt/librenms/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:31, PDOException(code: 1045): SQLSTATE[HY000] [1045] Access denied for user 'librenms'@'localhost' (using password: YES) at /opt/librenms/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27)

Ex. I can list the userids fine with info from config.php:
librenms@sea0020sas18:~$ echo ‘select user_id from users;’ | mysql -u librenms --password=sed -ne "/db_pass/{s/';$//;s/.*'//;p}" config.php librenms
user_id
1
4
7
10
5
2
3
11
12
8
9
6

Does anyone know what could have caused this?

I found out what the problem was.
I had a ‘#’ in the password and it was not qouted in the ~/.env file

2 Likes

I came in to the same issue this morning. I just went ahead and updated the password to remove the offending character.

Quotes around it would work.

where you do find the .enc file ?

i get the error below

Blockquote
#1 /opt/librenms/syslog.php(20): process_syslog()
#2 {main}
[2021-05-30 21:03:58] production.ERROR: SQLSTATE[HY000] [1045] Access denied for user ‘librenms’@‘localhost’ (using password: YES) (SQL: INSERT IGNORE INTO syslog (device_id,program,facility,priority,level,tag,msg,timestamp) VALUES (1,LIBRENMS-SERVICE.PY,daemon,info,info,1e,librenms(CRITICAL):DB Connection exception (1045, "Access denied for user 'librenms'@'localhost' (using password: YES)"),2021-05-30 21:03:58)) (SQL: INSERT IGNORE INTO syslog (device_id,program,facility,priority,level,tag,msg,timestamp) VALUES (1,LIBRENMS-SERVICE.PY,daemon,info,info,1e,librenms(CRITICAL):DB Connection exception (1045, "Access denied for user 'librenms'@'localhost' (using password: YES)"),2021-05-30 21:03:58))#0 /opt/librenms/includes/syslog.php(166): dbInsert()

Blockquote

I can see config .env but cant edit it
image

I changed the config.php to my current password

but im not sure what .env file you refer too

It should be
/opt/librenms/.env

In that file it is connection credentials for the database.