WordPress 7.2 and NO_BACKSLASH_ESCAPES: Check Your SQL Mode
WordPress 7.2 drops the NO_BACKSLASH_ESCAPES SQL mode for its own connection. Here is how to check your server, test on staging and fix it before 8 December.
The short answer
WordPress 7.2 removes NO_BACKSLASH_ESCAPES from the SQL modes of its own database session, without changing the server's global settings. If your server enables that mode, escaped values in queries can fail or return the wrong data. Check the global and WordPress session sql_mode, test on a staging copy, and remove the mode at the server if you can, or ask your host to.
Reading options
On this page
- What changed in WordPress 7.2
- What NO_BACKSLASH_ESCAPES actually is
- Before you start
- Step one: back up the database
- Step two: check the server's sql_mode
- Step three: check what the WordPress connection uses
- Step four: test on staging with the release candidate
- Step five: if you control the server, remove the mode
- Step six: if you cannot change the server
- How to check it worked
- Troubleshooting
- Security and host notes
- The one message worth forwarding
- Reader questions
- Sources & further reading
WordPress 7.2 switches off one MySQL setting, NO_BACKSLASH_ESCAPES, for its own database connection, and most sites will never notice. If your server turns that setting on, though, you want to know before 8 December, because WordPress and that mode disagree about what a backslash means.
The check takes about ten minutes. The awkward part is that the problem it guards against rarely announces itself, because odd database errors and wrong results are seldom traced back to a database setting.
By the end of this guide you will know whether your server uses the mode, what WordPress 7.2 will do about it, and exactly what to change or send to your host.
What changed in WordPress 7.2
The core team announced the change in October. In their words, "wpdb::set_sql_mode() now removes NO_BACKSLASH_ESCAPES from the session's SQL modes."
An SQL mode is a switch that changes how MySQL reads and checks queries. A session is one open connection between an application and the database, and each session carries its own copy of the modes.
The scope is narrow on purpose. The announcement says: "This affects only the WordPress database connection. It doesn't change the server's global settings."
Other apps on the same server keep their modes.
Why this matters: the announcement also says "Some hosts or server setups may turn this mode on." If yours does, WordPress 7.2 changes behaviour on your site the moment you update, even though nobody touched the server.
The release candidate post gives the date: "The scheduled release date for WordPress 7.2 is December 8, 2026." The change is tracked in Trac ticket #66185.
What NO_BACKSLASH_ESCAPES actually is
Inside a SQL query, text values sit between quote marks. If the text itself contains a quote mark, like the name O'Brien, the database needs a way to tell "this quote is part of the name" from "this quote ends the value."
WordPress handles that with a backslash. The core post puts it plainly: "WordPress uses the backslash character (\) to escape special characters in SQL queries."
The MySQL 8.4 manual describes the mode like this: "Enabling this mode disables the use of the backslash character (\) as an escape character within strings and identifiers."
Here is the everyday version. Think of the backslash as a sticky note on a parcel that says "the next item belongs inside the box." Normally the mail clerk reads the note and packs the item. With NO_BACKSLASH_ESCAPES on, the clerk ignores what the note says and packs the sticky note itself as if it were part of the delivery.
That is what the core post means when it says MySQL "reads the backslash as a normal character, not as an escape character." The next line is the one to remember: "Queries with escaped values can then fail or return the wrong data."
Heads up: the MySQL manual adds that with the mode on, "the default escape sequence for LIKE expressions is changed so that no escape character is used." LIKE is the pattern match behind many search boxes, so search is one of the places this shows up.
Made-up example: a small bakery site runs a catering enquiry form. A customer named Siobhan O'Neill submits it, and the entry never reaches the admin screen. Another customer types a Windows file path into a notes field, and it comes back with the slashes doubled. Weeks pass before anyone looks at the database server's sql_mode line. None of this happened to a real site; it is the shape of the problem.
Before you start
Run through this list first. It takes a couple of minutes and saves you from fixing the wrong thing.
- You can log in to the WordPress admin, and ideally you have SSH access with WP-CLI installed.
- You know whether you are on shared hosting or on a server where you have root access.
- You have a fresh backup of the database, or you are about to make one in the first step below.
- You have, or can make, a staging copy of the site for testing the 7.2 release candidate.
- You know whether a file called
db.phpalready exists in yourwp-contentfolder, because one of the fixes below creates it.
Quick tip: if you have not used WP-CLI with backups before, our guide on backing up WordPress with WP-CLI walks through it slowly. For the wider 7.2 timeline, the WordPress 7.2 readiness plan covers versions, staging and dates, and this post stays on the SQL mode question only.
Step one: back up the database
You are only reading settings for most of this guide. You still want a backup, because the later steps change a config file or add a drop-in, and any of those can go sideways.
Export with WP-CLI
Run this command from the folder where WordPress is installed to write a full SQL dump of the site's database.
wp db exportAccording to the WP-CLI documentation, if you do not name a file, the export is saved as {dbname}-{Y-m-d}-{random-hash}.sql in the current folder. You can name it yourself if you prefer something easier to find.
To choose the file name yourself, pass it as the first argument, as in this example.
wp db export before-sqlmode-check.sqlMove that file somewhere outside the public web folder once it finishes. A database dump sitting in public_html can be downloaded by anyone who guesses the name.
Or use your control panel's backup tool
No SSH? Use the backup or database download tool in your hosting control panel and save the copy to your own computer. Either way, check that the file is not suspiciously small.
Step two: check the server's sql_mode
This is the heart of the check. You are asking MySQL two questions: what is the server-wide default, and what does a given connection actually use.
The MySQL manual gives the exact statements: "To determine the current global or session sql_mode setting, select its value:"
SELECT @@GLOBAL.sql_mode;
SELECT @@SESSION.sql_mode;The global value is the default that new connections start from. The session value is what one particular connection is using right now, after any changes it made to itself.
Option A: from a root shell on a cPanel server
On a cPanel server you can open a root shell through SSH or through WHM at "Home / Server Configuration / Terminal." Then run the same check cPanel's own support article uses.
mysql -e 'select @@GLOBAL.sql_mode;'Option B: from the site with WP-CLI
If you are not root, WP-CLI can run the query using the database user from wp-config.php. The command below asks for the global value only.
wp db query 'SELECT @@GLOBAL.sql_mode' --skip-column-namesWhy prefer @@GLOBAL here? The WP-CLI docs explain that by default, "the incompatible modes that WordPress disables in wpdb" are "stripped for the session." So a session value read through wp db query has already been cleaned up by WP-CLI and can hide the very thing you are looking for. The global value is not touched by that compatibility step.
If you want to see the session exactly as the server hands it out, the docs describe a flag that turns the clean-up off: --skip-sql-mode-compat will "Run the query under the server's own SQL modes instead of adapting them to be WordPress-compatible."
Run this command to see the raw session modes the server gives a fresh connection.
wp db query 'SELECT @@SESSION.sql_mode' --skip-column-names --skip-sql-mode-compatRead the result
You get one comma-separated line. Look for the exact word NO_BACKSLASH_ESCAPES anywhere in it.
For comparison, the MySQL 8.4 manual lists the default modes as ONLY_FULL_GROUP_BY, STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO and NO_ENGINE_SUBSTITUTION. NO_BACKSLASH_ESCAPES is not in that default list, so if you see it, someone or something added it.
Heads up: if your server runs MariaDB instead of MySQL, the commands above still work, but MariaDB keeps its own default list. Compare your output against the MariaDB documentation for your version, not the MySQL list above.
Step three: check what the WordPress connection uses
The global value tells you what WordPress starts with. What actually matters is the session WordPress ends up with after its own wpdb::set_sql_mode() runs.
Ask WordPress directly
The wp eval command, which the docs describe as "Executes arbitrary PHP code," loads WordPress and runs a line of PHP. This command asks the live $wpdb connection for its session modes.
wp eval 'global $wpdb; echo $wpdb->get_var( "SELECT @@SESSION.sql_mode" );'The get_var() method "Executes a SQL query and returns the value from the SQL result," so you get the modes back as a single line.
On WordPress 7.1 or earlier, if the global value contained NO_BACKSLASH_ESCAPES, you will usually see it here too. On a site running 7.2, it should be gone, unless something has filtered it back in.
Why this matters: this is the only one of the three checks that shows you what WordPress itself sees. The other two describe the server around it.
Step four: test on staging with the release candidate
Knowing the mode is on tells you there is a risk. Testing tells you whether anything on your particular site actually depends on it.
The release candidate announcement is blunt about where not to do this: "Please do not install, run, or test this version of WordPress on production or mission-critical websites."
Put the staging copy on 7.2 RC3
On the staging copy only, run the update command given in the RC3 announcement.
wp core update --version=7.2-RC3If you prefer the admin screen, the announcement also describes the WordPress Beta Tester plugin with the "Bleeding edge" channel and the "Beta/RC Only" stream. After 8 December, test against the current release instead.
Rerun the connection check
Once the staging site is on the release candidate, run the wp eval command from step three again and compare the two lines.
Click through the parts that touch text
Then test the things that pass quotes and backslashes around. Save a post with an apostrophe in the title, submit each form with a name like O'Brien, run a site search, and open any plugin screen that imports or exports data.
Quick tip: note anything that looked wrong before the update and now looks right, so nobody "fixes" it back later.
Step five: if you control the server, remove the mode
If you have root, the cleanest fix is to stop the server enabling the mode at all. Every application on the box then gets normal backslash handling.
cPanel's article on editing MySQL settings mentions a WHM screen at "Home / SQL Services / Edit SQL Configuration," and adds that "Not all options are exposed in this interface." For this change, go straight to the config file.
Copy the current value
Run the global check again and copy the whole line somewhere safe before you change anything.
mysql -e 'select @@GLOBAL.sql_mode;'Edit the config file
Open /etc/my.cnf with the editor you are comfortable with.
nano /etc/my.cnfFind the line that sets sql_mode. cPanel's strict mode article says to add one at the end of the file if none exists. Rewrite the line using the value you copied, minus NO_BACKSLASH_ESCAPES.
This illustration uses the MySQL 8.4 default list. Use your own server's modes.
sql_mode = "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"Heads up: drop only the one mode. Removing other modes at the same time turns a small, testable change into a large one, and any mode change can make applications that relied on the old setting behave differently.
Restart MySQL and recheck
Restart the database service with the cPanel script from its strict mode article.
/scripts/restartsrv_mysql --forceThen confirm the new value took effect.
mysql -e 'select @@GLOBAL.sql_mode;'You can also change the running server with SET GLOBAL sql_mode = 'modes';, but that value is lost on the next restart. Use it only to test, and put the permanent version in /etc/my.cnf.
Step six: if you cannot change the server
On shared hosting you will not have root, so you cannot change the global mode yourself. The first move is to ask the host, and the message at the end of this post is written for exactly that.
Most sites should then simply update to 7.2 and let WordPress drop the mode for its own connection. That is the whole point of the change.
Keeping the mode on purpose
A small number of sites have custom code written around NO_BACKSLASH_ESCAPES and genuinely need it. If that is you, the core post gives an escape hatch using the existing incompatible_sql_modes filter.
The timing rule matters. The post says: "WordPress connects to the database before plugins load, so add this code in a db.php drop-in." It also warns, "Code in a normal plugin or a must-use plugin runs too late."
A drop-in is a special file WordPress loads by name from the content folder. WordPress core's require_wp_db() function checks for WP_CONTENT_DIR . '/db.php' and loads it before creating the database object, and WP_CONTENT_DIR is your wp-content folder on a standard install.
First, check whether a db.php already exists.
ls -l wp-content/db.phpIf that command lists a file, stop. Some caching and debugging plugins ship their own db.php, and overwriting it breaks them. Talk to that plugin's author instead of replacing their file.
If no file exists, create wp-content/db.php with the snippet from the core announcement, plus the opening PHP tag.
<?php
add_filter( 'incompatible_sql_modes', function ( $modes ) {
return array_diff( $modes, array( 'NO_BACKSLASH_ESCAPES' ) );
} );Leave out a closing ?> tag, so stray whitespace at the end of the file cannot leak into page output. Because the file does not define its own $wpdb, require_wp_db() carries on and creates the normal database object after loading it.
Heads up: the core post itself says "WordPress Core may not work correctly with this mode turned on," and the field guide warns this "may introduce compatibility issues with Core." Treat this as a stopgap while the custom code is fixed.
How to check it worked
Run three checks and compare them with what you expect.
First, the server's global value. If you removed the mode from /etc/my.cnf, it should be gone.
mysql -e 'select @@GLOBAL.sql_mode;'The output is a header line followed by the value. On a server matching the MySQL 8.4 defaults, it looks something like this.
@@GLOBAL.sql_mode
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTIONSecond, the WordPress connection on the 7.2 staging site.
wp eval 'global $wpdb; echo $wpdb->get_var( "SELECT @@SESSION.sql_mode" );'Expect a single comma-separated line with no NO_BACKSLASH_ESCAPES in it. WordPress also removes its other incompatible modes for its session, so this line is often shorter than the global value. That is normal.
If you added the db.php filter, expect the opposite: NO_BACKSLASH_ESCAPES stays in the WordPress session. If it does not, the drop-in is not loading.
Third, the human check. Save a post titled Pat's "test" post, search for it, and submit a form with an apostrophe. Everything should come back exactly as typed, with no extra backslashes and no missing quotes.
Troubleshooting
Saved text shows extra backslashes
Symptom: content comes back as O\'Brien or a path shows \\ where you typed \. Cause: a likely one is that the mode was on for the connection that wrote the data, so backslashes were treated as ordinary characters. Fix: confirm the mode with the session check, remove it or update to 7.2, then clean up the affected rows after you have a backup.
A form submission disappears or fails
Symptom: entries with apostrophes never arrive, while entries without them do. Cause: with backslash escaping off, escaped values can fail or return the wrong data, which can include a quote inside the value ending the string early. Fix: check the WordPress connection's modes, then test the form again on staging with 7.2 or with the mode removed from the server.
"Access denied" when you run SET GLOBAL
Symptom: you get an error containing Access denied when you run SET GLOBAL sql_mode. Cause: the MySQL manual says setting the global variable "requires the SYSTEM_VARIABLES_ADMIN privilege (or the deprecated SUPER privilege)," and a site's database user normally lacks it. Fix: run the change as root, or on shared hosting, ask your host to do it.
MySQL will not start after editing /etc/my.cnf
Symptom: /scripts/restartsrv_mysql --force reports a failure and sites show database connection errors. Cause: usually a typo in the sql_mode line, such as a misspelled mode name or a missing quote. Fix: restore the line you copied earlier, restart again, then make the single edit more carefully.
The db.php filter has no effect
Symptom: the wp eval check still shows no NO_BACKSLASH_ESCAPES after you added the filter. Cause: the file is in the wrong folder, has a syntax error, or the code went into a plugin instead. Fix: confirm the file sits directly in wp-content, run php -l wp-content/db.php to check its syntax, and remember that plugin code runs too late.
Search stops matching after the change
Symptom: a custom search that used to work returns different results once the mode is off. Cause: the MySQL manual notes the mode also changes the escape behaviour of LIKE patterns, and some custom code may have been written around that. Fix: find the custom query, look at how it escapes % and _, and adjust it to the normal backslash rules.
If the database looks damaged after any of this, our guide to checking and repairing a WordPress database with WP-CLI and cPanel covers the next steps.
Security and host notes
Escaping is part of how queries stay safe from injected input, so code and database must agree on what the escape character is.
Keep the db.php override for cases where you know exactly which code needs the mode and why. If nobody can name that code, you probably do not need the override.
Shared hosting customers cannot change the global SQL mode without root access. That is a host decision, so put the question to them in writing.
The one message worth forwarding
Copy this, fill in your domain, and send it to your host's support desk.
Hello,
WordPress 7.2 is scheduled for 8 December 2026. It removes the MySQL mode NO_BACKSLASH_ESCAPES from the WordPress database session (Trac ticket #66185).
Could you please tell me:
1. Is NO_BACKSLASH_ESCAPES in the global sql_mode for the database server that hosts example.com?
2. If it is, was it enabled on purpose, and can it be removed from the server's sql_mode setting?
3. If it cannot be removed, is there any reason a db.php drop-in on my site would conflict with your setup?
The output of SELECT @@GLOBAL.sql_mode; would answer the first question.
Thank you.If NO_BACKSLASH_ESCAPES is not in your sql_mode output, you are done; if it is, test on staging before 8 December and fix it at the server rather than in WordPress.
Reader questions
Will WordPress 7.2 change my server's MySQL settings?
No. The change applies only to the database session WordPress opens, and the server's global sql_mode stays as it is for every other application.
Do I need to do anything if NO_BACKSLASH_ESCAPES is not in my sql_mode?
No action is needed for this particular change. You can update to WordPress 7.2 as you normally would once your usual testing is done.
Will WordPress 7.2 fix old data that already has stray backslashes?
No. The change affects how new queries run, and rows already stored stay as they are. Clean those up by hand after taking a backup.
Should I still remove the mode from the server after updating to 7.2?
Usually yes, if nothing else depends on it. Other applications on the server still get the global mode, so test them before and after the change.
Does this affect sites on MariaDB?
The same sql_mode checks work on MariaDB. MariaDB keeps its own list of default modes, so compare your output against the MariaDB documentation for your version.
Do I need to edit wp-config.php for any of this?
No. WP-CLI reads the database credentials from wp-config.php on its own, and none of the fixes in this guide change that file.
Was this guide helpful?
Help us make the next update better.
Sources & further reading
- Make WordPress Core: NO_BACKSLASH_ESCAPES SQL mode is now turned off by default in WordPress 7.2
- WordPress 7.2 Release Candidate 3
- WordPress 7.2 Field Guide
- MySQL 8.4 Reference Manual: Server SQL Modes
- WP-CLI: wp db query
- WP-CLI: wp db export
- WordPress Developer Reference: require_wp_db()
- cPanel Support: How to edit the MySQL/MariaDB configuration (my.cnf) file
- cPanel Support: How to disable MySQL Strict Mode
Originally published . About our editorial updates.



