VillageSQL is a drop-in replacement for MySQL with extensions.
All examples in this guide work on VillageSQL. Install Now →
Combining and Splitting
CONCAT — join strings together:CONCAT with a NULL argument returns NULL. CONCAT_WS skips NULL values but keeps the separator for non-NULL ones.
SUBSTRING / SUBSTR / MID — extract part of a string:
Searching Within Strings
LOCATE / POSITION / INSTR — find a substring:REGEXP uses POSIX regex syntax. Use REGEXP_LIKE() (MySQL 8.0+) for the function form.
Modifying Strings
REPLACE — replace all occurrences of a substring:Length and Comparison
MySQL has two length functions that produce different results for multibyte characters:| Function | What it measures |
|---|---|
LENGTH(s) | Byte length |
CHAR_LENGTH(s) / CHARACTER_LENGTH(s) | Character length |
CHAR_LENGTH when you care about the number of characters, not bytes.
STRCMP — compare two strings, returns -1, 0, or 1:
Formatting
FORMAT — format a number with thousands separators:Common Patterns
Extract the domain from an email address:Frequently Asked Questions
Are MySQL string comparisons case-sensitive?
By default, no — string comparisons use the column’s collation, and most common collations are case-insensitive (e.g.,utf8mb4_general_ci, where ci = case-insensitive). For case-sensitive comparisons, use a _cs collation or the BINARY operator:
What’s the difference between CHAR_LENGTH and LENGTH?
LENGTH returns byte count; CHAR_LENGTH returns character count. For ASCII strings they’re the same. For UTF-8 strings with multibyte characters (accented letters, emoji, CJK), they differ. Use CHAR_LENGTH for user-visible string length limits.
Troubleshooting
| Problem | Solution |
|---|---|
CONCAT returns NULL | One argument is NULL — use COALESCE(col, '') to replace NULLs before concatenating, or use CONCAT_WS |
LIKE '%pattern%' is slow | Leading wildcard prevents index use — consider FULLTEXT index for text search at scale |
| String comparison not matching expected rows | Case sensitivity or collation mismatch — check the column’s collation with SHOW CREATE TABLE |
REPLACE updates more rows than expected | REPLACE is case-insensitive by default — it replaces all case variants of the target string |
SUBSTRING returns empty string, not NULL | SUBSTRING of an out-of-range position returns an empty string, not NULL |

