Searching for backslash (\) in MySQL 5.7, for the escape when LIKE, you need to use \\\\
1. The data in the table is as follows
INSERT INTO `object_store`.`theme_asset`(`id`, `theme_id`, `version`, `asset_key`, `mime_type`, `category`, `schema`, `created_at`, `updated_at`) VALUES (63, 'vogue', '', 'layouts\\basic.blade.php', 'text/html', 'unknown', NULL, '2022-02-15 09:59:41', '2022-02-15 09:59:41');
2. When executing a where like query, use likelayouts\\%Attempts to query the data rows starting with Layouts\. The result is empty. as shown in Figure 1
select
`id`,
`theme_id`,
`version`,
`asset_key`,
`mime_type`,
`category`,
`schema`,
`created_at`,
`updated_at`
from
`theme_asset`
where
(
`theme_id` = 'vogue'
and `asset_key` like 'layouts\\%'
)
3. When executing a where like query, use likelayouts\\\%Attempts to query the data rows starting with Layouts\. Only the corresponding results are actually searched. as shown in Figure 2
select
`id`,
`theme_id`,
`version`,
`asset_key`,
`mime_type`,
`category`,
`schema`,
`created_at`,
`updated_at`
from
`theme_asset`
where
(
`theme_id` = 'vogue'
and `asset_key` like 'layouts\\%'
)
4. Reference:https://dev.mysql.com/doc/refman/5.7/en/string-comparison-functions.html. MySQL uses the C escape syntax in strings (for example, \n means newlines). If you want the like string to contain literal \, you must double it. (Unless you use the escape character in this case, unless the NO_BACKSLASH_ESCAPES SQL mode is enabled.) For example, to search \n, specify it as \n. To search for \, specify it as \\\\; this is because the backslash is stripped by the parser once, and it is stripped again when a pattern match is made, leaving a backslash to match. as shown in Figure 3


