MySQL Query Formatter โ Format MySQL SQL Online Free
Format and beautify MySQL queries with proper indentation, uppercase keywords, and consistent alignment. Supports all MySQL-specific syntax.
MySQL has some quirks in its SQL dialect that affect how you should write and format queries. Understanding them helps you write cleaner MySQL-specific code and avoid portability traps if you ever switch databases.
MySQL-specific formatting considerations
MySQL uses backtick quoting for identifiers (table and column names), unlike PostgreSQL which uses double quotes and SQL Server which uses square brackets. If your identifiers are reserved words or contain spaces, backtick them:
-- MySQL: backtick quoting SELECT `user`.`id`, `order`.`total` FROM `user` JOIN `order` ON `order`.`user_id` = `user`.`id`; -- Better: avoid reserved words as table names SELECT u.id, o.total FROM users u JOIN orders o ON o.user_id = u.id;
MySQL-specific functions to format consistently
-- Date/time formatting (MySQL-specific) SELECT id, DATE_FORMAT(created_at, '%d-%m-%Y') AS date_str, DATEDIFF(NOW(), created_at) AS days_old, TIMESTAMPDIFF(MONTH, created_at, NOW()) AS months_old FROM orders WHERE created_at >= DATE_SUB(NOW(), INTERVAL 90 DAY);
GROUP_CONCAT: MySQL's array aggregation
-- Aggregate related data as comma-separated string
SELECT
u.id,
u.name,
GROUP_CONCAT(
t.name
ORDER BY t.name
SEPARATOR ', '
) AS tags
FROM users u
LEFT JOIN user_tags ut ON ut.user_id = u.id
LEFT JOIN tags t ON t.id = ut.tag_id
GROUP BY u.id, u.name;EXPLAIN for query optimization
-- Always check the query plan for slow queries EXPLAIN SELECT * FROM orders WHERE user_id = 123; -- More detailed (MySQL 8+) EXPLAIN ANALYZE SELECT * FROM orders WHERE user_id = 123;
Look for type: ALLin the output (full table scan). That's a signal you need an index on the filtered column.
Consistent formatting saves debugging time
Copy any MySQL query into our SQL Formatter and format it before pasting into documentation or asking for help in Slack. Formatted SQL gets better answers faster.