If you need to generate URL-friendly slugs directly in MySQL or MariaDB — for example, turning “My Product Name” into “my-product-name” — you can do it with a single UPDATE statement.

UPDATE my_table
SET slug = LOWER(REGEXP_REPLACE(REPLACE(REPLACE(REPLACE(name, ' ', '-'), 'and', '-'), '[^a-zA-Z0-9-]', ''), '-+', '-'));

This chains a few string functions together: spaces become hyphens, special characters get stripped, “and” is replaced with a hyphen, and everything is lowercased. The REGEXP_REPLACE at the end cleans up any consecutive hyphens that might result from the replacements.

This is useful for backfilling slugs on existing data or migrating from a system that didn’t generate slugs. For new records, it’s generally better to generate slugs in your application code where you have more control over edge cases like unicode characters, leading/trailing hyphens, and duplicate slug handling.