Help with Database Connection Error in WordPress When Running Matomo Archiving

I am experiencing issues with my WordPress site when trying to run the archiving function for the Matomo analytics plugin. The error indicates a problem with establishing a database connection.

Here are the details of the error:

Matomo Archive Warnings: 'Got invalid response from API request: ?module=API&method=CoreAdminHome.archiveReports&idSite=1&period=day&date=2024-05-21&format=json&trigger=archivephp. Response was 'Matomo error: 2: mysqli_real_connect(): (HY000/2002): No such file or directory in $abs_path/wp-includes/class-wpdb.php:1987

The system diagnostics report shows that the last successful archiving was on May 16, 2024, and since then, there have been multiple unsuccessful attempts. Here are some additional system details:

  • WordPress Version: 6.5.3
  • PHP Version: 8.1.23
  • MySQL Version: 8.0.35
  • Server: nginx/1.24.0
  • Matomo Plugin Version: 5.0.6

The error message “No such file or directory” suggests an issue with the MySQL socket file. It seems the PHP configuration might be pointing to a wrong or missing MySQL socket file, or the MySQL server might not be running.

Here’s what I have checked so far:

  1. Database credentials in wp-config.php are correct.
  2. The MySQL server is running (according to my hosting service).
  3. No recent changes were made to the PHP or MySQL configuration that could lead to this issue.

I would appreciate any advice on how to troubleshoot this problem further or any configurations that I should verify to resolve this error.