I poked around for the problem and found this in sql-mode Help:   Note that SQL doesn't have an escape character unless you specify   one.  If you specify backslash as escape character in SQL, you   must tell Emacs.  Here's how to do that in your init file:   (add-hook 'sql-mode-hook             (lambda ()               (modify-syntax-entry ?\\ "." sql-mode-syntax-table))) And sure enough, the syntax of \ was punctuation. However, adding the above add hook did nothing. The string highlighting was still wrong. It's because the suggestion is wrong, because it sets slash to punctuation again. Somebody who has access to the repo could simply fix that by changing the syntax string in the example:   (modify-syntax-entry ?\\ "\\" sql-mode-syntax-table) So it worked, but then I realized there are different sql modes and the default is ANSI, so I changed it to Mysql to test it, but that didn't help either. Then I checked the mysql syntax setting and backslash was missing there too, though backslash is an escape character for mysql by default:   https://dev.mysql.com/doc/refman/8.0/en/string-literals.html So I changed the syntax for mysql by adding backslash:            :syntax-alist ((?# . "< b") (?\\ . "\\")) and this fixed it. There are 3 takeaways: 1. The incorrect example in sql-mode Help should be fixed. 2. Since backslash is an escape character in mysql it may be set as    such by default if the user chooses mysql mode. 3. The user may not realize he is in an incorrect sql mode. Maybe when    the user activates sql mode for the first time emacs should tell him    that ansi is the default and ask him if he wants to change it?