Problem/Motivation
Drupal automatically executes a SET NAMES utf8mb4 query when opening a MySQL/MariaDB database connection. For sites with database servers already configured with utf8mb4 as the default character set (or specialized proxy/clustering configurations), this extra query adds unnecessary connection overhead and latency.
Proposed resolution
Allow sites to opt out of the automatic SET NAMES query by specifying 'set_names' => FALSE (or 'skip_set_names' => TRUE) in the database connection options array in settings.php.
- Support set_names and skip_set_names in both mysql and mysqli database drivers.
- Document the setting in default.settings.php.
- Add Kernel test coverage in ConnectionTest.
Remaining tasks
- Review MR
- Maintainer review
User interface changes
None
Introduced terminology
None
API changes
Added optional set_names (boolean) and skip_set_names (boolean) connection options to database configuration.
Data model changes
None
Release notes snippet
MySQL and MariaDB database connections now support opting out of the automatic SET NAMES utf8mb4 query by setting 'set_names' => FALSE in $databases settings.
Issue fork drupal-2575733
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #15
smustgrave commentedThank you for creating this issue to improve Drupal.
We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #16
smustgrave commentedWanted to check 1 more time if still valid?
Comment #17
ghost of drupal pastIt's one of those things that would be good but so minor no one actually picked it up. Is there anyone doing guided contribution hours? It's not too bad for a first issue although certainly bigger than just fixing a minor typo in docs.
Comment #19
smustgrave commentedLets keep open then just in case. Thanks!
Comment #20
catchLet's tag it novice and see how it goes. The issue summary is eleven years old now, but I think it's probably still about the same - we can add an opt out flag to the connection options, and check that before sending the query.
Comment #21
keerthi kumar commentedComment #22
keerthi kumar commentedI'll be working on this!
Comment #24
keerthi kumar commentedMerge Request has been opened and is ready for review!
Comment #25
smustgrave commentedNeed to ask as this is kinda reading like AI was it used?
Per https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquett...
Comment #26
keerthi kumar commentedHey, @smustgrave,
Yes, I used AI to help me navigate the codebase and draft the tests, but I went through the changes and understand the implementation.
Following catch's comment, the goal was just to let people opt out of running `SET NAMES` on connection if their server already defaults to utf8mb4, since PDO already has the charset in the DSN and mysqli calls `set_charset()`.
Comment #27
keerthi kumar commented