Error in Matomo (tracker): Error while connecting to the Matomo database - please check your credentials in config/config.ini.php file

hi
i have this error in php log file.
“Error in Matomo (tracker): Erorr while connecting to the Matomo database - please check your credentials in config/config.ini.php file”

please help me.

Hi,

The error is exactly what it says.

Matomo tries to connect to the MySQL/MariaDB database and fails. So maybe the credentials you entered are not correct. (you can check at config/config.ini.php).

And I think you can see the exact error message in the Matomo log (https://matomo.org/faq/troubleshooting/faq_115/)

matomo connect to db and show login page.I check database have new data

It is possible that after installing and using Matomo, your database credentials has been changed so please cross check username, password, database and host against your database in Matomo/config/config.ini.php

my connection string to db is correct but i have this error:
" Error in Matomo (tracker): Error while connecting to the Matomo database - please check your credentials in config/config.ini.php file"

Hi @ariyoweb ? Please try the following attached code snippet. I have written to test the db connection. It is simple PHP code. I hope you will understand. If your db connect will work then there would be output like Rows: otherwise some error or no output.

<?php
/* 
**Matomo configuration file path. Please update the following path according to your system.
*/
$matomo_config_path="/var/www/html/matomo/config/config.ini.php";
$ini_array = parse_ini_file($matomo_config_path);

function OpenCon($ini_array)
{
    $dbhost = $ini_array["host"];
    $dbuser = $ini_array["username"];
    $dbpass = $ini_array["password"];
    $db = $ini_array["dbname"];
    $conn = new mysqli($dbhost, $dbuser, $dbpass, $db) or die("Connect failed: %s\n" . $conn->error);
    return $conn;
}
$conn = OpenCon($ini_array);
try
{
    if(array_key_exists("tables_prefix",$ini_array))
    {
    	$tables_prefix=$ini_array['tables_prefix'];
    }
    else{
    	$tables_prefix="matomo_";
    }
    $sql = "SELECT * FROM $tables_prefix"."log_conversion";

    $result = $conn->query($sql);
    if ($result->num_rows > 0)
    {
        echo "Rows count: ".$result->num_rows;
    }
}
catch(Exception $e)
{
    echo "Connection failed: " . $e->getMessage();
}
?>

Hi,

If parts of Matomo like the login work without an issue and other parts show a database issue, then your MySQL user might not have all the permissions it needs. Especially the CREATE TEMPORARY TABLES permission is often not given, but required by Matomo. So try granting your MySQL user this permission and see if the issues disappear.

The MySQL USER should have the permission to SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, FILE.
https://matomo.org/docs/requirements/

And again, if you don’t want to guess wildly: The exact error message should be shown in the Matomo log.

hi
I can connect to database but i have below errors:
[02-Oct-2021 10:06:35 UTC] Error in Matomo (tracker): Error while connecting to the Matomo database - please check your credentials in config/config.ini.php file
[02-Oct-2021 10:06:37 UTC] Error in Matomo (tracker): Error query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘0’ for key ‘PRIMARY’ In query: INSERT INTO matomo_log_action (name, hash, type, url_prefix) VALUES (?,CRC32(?),?,?) Parameters: array ( 0 => ‘zn.ihio.gov.ir/Zanjan > shohada’, 1 => ‘zn.ihio.gov.ir/Zanjan > shohada’, 2 => 4, 3 => NULL, )
[02-Oct-2021 10:06:37 UTC] Error in Matomo (tracker): Error query: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘0’ for key ‘PRIMARY’ In query: INSERT INTO matomo_log_action (name, hash, type, url_prefix) VALUES (?,CRC32(?),?,?) Parameters: array ( 0 => ‘siteurl’, 1 => ‘siteurl’, 2 => 1, 3 => 2, )
[02-Oct-2021 10:06:41 UTC] Error in Matomo (tracker): Error while connecting to the Matomo database - please check your credentials in config/config.ini.php file
[02-Oct-2021 10:06:42 UTC] Error in Matomo (tracker): Error while connecting to the Matomo database - please check your credentials in config/config.ini.php file
[02-Oct-2021 10:06:43 UTC] Error in Matomo (tracker): Error while connecting to the Matomo database - please check your credentials in config/config.ini.php file
[02-Oct-2021 10:06:43 UTC] Error in Matomo (tracker): Error while connecting to the Matomo database - please check your credentials in config/config.ini.php file
[02-Oct-2021 10:06:43 UTC] Error in Matomo (tracker): Error while connecting to the Matomo database - please check your credentials in config/config.ini.php file
[02-Oct-2021 10:06:45 UTC] Error in Matomo (tracker): Error while connecting to the Matomo database - please check your credentials in config/config.ini.php file
[02-Oct-2021 10:06:45 UTC] Error in Matomo (tracker): Error while connecting to the Matomo database - please check your credentials in config/config.ini.php file
[02-Oct-2021 10:06:46 UTC] Error in Matomo (tracker): Error while connecting to the Matomo database - please check your credentials in config/config.ini.php file
[02-Oct-2021 10:06:47 UTC] Error in Matomo (tracker): Error while connecting to the Matomo database - please check your credentials in config/config.ini.php file

hi
I can connect to database.