Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Usage Milestone: Google Analytics Module google_analytics crossed 1,000 active installs. Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Release: GraphQL Compose Codegen 1.1.2 Minor update available for module graphql_compose_codegen (1.1.2). Release: Mapy.com 1.1.3 Minor update available for module mapycom (1.1.3). Release: Ckeditor5 entity browser 3.0.3 Minor update available for module ckeditor5_entity_browser (3.0.3). Release: Ckeditor5 entity browser 3.0.1 Minor update available for module ckeditor5_entity_browser (3.0.1). Release: Ckeditor5 entity browser 3.0.2 Minor update available for module ckeditor5_entity_browser (3.0.2). Release: Teamleader Integration 4.0.2 Minor update available for module teamleader (4.0.2). Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

MySQL/MariaDB Query Logger

No security coverage Drupal 10–11
View on drupal.org

This module logs all database queries made by Drupal to a custom file. It records the timestamp, operation type, execution time, and the query itself for each database activity.

mysql_query_logger is a minimal module that logs all Drupal database activity to a custom file. You do not need to install or enable the module via the Drupal UI—simply add the code via Composer and update your database configuration.

Features

This module provides a custom MySQL driver for Drupal 10, which extends the standard driver and logs every database operation (SELECT, INSERT, UPDATE, DELETE, MERGE, etc.).

Each log entry includes:

  • Timestamp
  • Operation type
  • Execution time
  • Query details (JSON formatted for easy analysis)

Example log line:

[2024-06-27 16:38:15] INSERT (0.003521 s): ["users",{"fields":{"name":"testuser"}}]

Installation

1. Install via Composer

It's recommended to add the module to your project using Composer. If not already distributed via a Composer repository, you can use path repositories.

composer config repositories.mysql_query_logger path 'modules/custom/mysql_query_logger'
composer require drupal/mysql_query_logger:*

Or, if already published to a VCS or Packagist:

composer require drupal/mysql_query_logger

Note: Adapt the path if your module resides elsewhere.

2. Update Database Settings

Open settings.php and adjust your database configuration as follows (usually at the end of the file):

// Settings to record database activity.
$databases['default']['default']['driver'] = 'mysql_query_logger';
$databases['default']['default']['namespace'] = 'Drupal\mysql_query_logger\Driver\Database\mysql_query_logger';
$databases['default']['default']['autoload'] = 'web/modules/custom/mysql_query_logger/src/Driver/Database/mysql_query_logger/Connection.php';
// Set an absolute or relative path for your log output file.
$databases['default']['default']['output'] = '/absolute/path/mysql_query_logger.log';

require_once DRUPAL_ROOT . '/core/modules/mysql/src/Driver/Database/mysql/Connection.php';
require_once DRUPAL_ROOT . '/modules/custom/mysql_query_logger/src/Driver/Database/mysql_query_logger/Connection.php';

TIP: Adjust the autoload and output paths to match your project structure.

3. Permissions

Ensure that PHP has write access to the log file location. For example:

touch /absolute/path/mysql_query_logger.log
chmod 664 /absolute/path/mysql_query_logger.log
chown www-data:www-data /absolute/path/mysql_query_logger.log

Removal

To disable the logger, simply remove or comment out the custom database settings in your settings.php. You can then remove the module via Composer if desired.

Security & Usage Notes

  • Production caution: Do not use this module in production without considering log size and sensitivity.
  • Log files can grow quickly on high-traffic sites.
  • Logs may contain sensitive queries (e.g., tokens, hashed passwords).

Support

This module is offered “as-is” and is intended primarily for development, debugging, and auditing scenarios.

Alternatives

  • Use Symfony query logger or Xdebug for PHP.
  • Consider the Drupal Database Logging or Query Monitor modules.
  • Enable the MySQL Slow Query Log at the database server level.

Note:

When using this module as your database driver, certain configuration export/import operations and other Drush utilities may stop working or behave unexpectedly. This is because some Drupal and Drush commands depend on the default database driver or expect specific behaviors not implemented in this custom driver. For critical Drush tasks, we recommend temporarily reverting to the standard MySQL driver.

Depends on

Dependencies of the latest stable release

  • mysql Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Jul 2025
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 2
Maintenance
Dormant

Releases

Version Type Core Release date
1.0.0 Stable 10–11 Jul 8, 2025
1.0.x-dev Dev 10–11 Jul 8, 2025