Databases 7 min read

Hidden MySQL Tricks You Probably Missed

This article compiles a series of lesser‑known MySQL details—from case‑insensitive column names and fuzzy LIKE patterns to REPLACE INTO, INSERT … ON DUPLICATE KEY UPDATE, EXPLAIN usage, index length limits, replication methods, partitioning, slow‑query monitoring, binlog importance, advanced objects like views and stored procedures, and recommended client tools—helping developers avoid common pitfalls and write more efficient queries.

ITPUB
ITPUB
ITPUB
Hidden MySQL Tricks You Probably Missed

Case Insensitivity (Column Names)

MySQL treats column names as case‑insensitive, but the data values are case‑sensitive. Therefore, avoid using mixed‑case naming for columns; use underscores instead.

Examples:

SELECT uid, v_state FROM all_user WHERE username = 'sunyue';
SELECT uid, v_state FROM all_user WHERE USERNAME = 'sunyue';  // same result, column name case ignored
SELECT uid, v_state FROM all_user WHERE USERname = 'SUNYUE';  // no rows, value case matters

Fuzzy Matching ([_] matches any character)

MySQL supports simple pattern matching with LIKE. Use _ for a single character and % for any sequence of characters.

SELECT uid, v_state FROM all_user WHERE USERNAME LIKE 'su_yue';  // '_' matches any single character
SELECT uid, v_state FROM all_user WHERE USERNAME LIKE 'su%yue';  // '%' matches any number of characters
SELECT uid, v_state FROM all_user WHERE USERNAME NOT LIKE 'su%';  // exclude rows matching pattern

How to Guess a Feature

MySQL aims to be developer‑friendly. If you understand basic English and relational concepts, you can often infer the correct syntax for an unknown feature, because well‑designed commands are usually intuitive.

REPLACE INTO Syntax

REPLACE INTO

performs a forced insert that overwrites existing rows with the same primary key. Use it only when you need an “upsert” behavior and the table does not rely on auto‑increment IDs, as it wastes ID values.

INSERT INTO … ON DUPLICATE KEY UPDATE Syntax

This more graceful upsert syntax inserts a row, but if a duplicate key conflict occurs, it updates the existing row instead. It is slower than REPLACE but safer for tables with auto‑increment columns.

EXPLAIN Syntax

The EXPLAIN command shows how MySQL executes a query, helping you identify whether the statement is optimized and where bottlenecks lie. Frequent use can greatly improve query performance.

Index Length

Maximum index lengths differ by storage engine: MyISAM allows up to 1000 bytes, while InnoDB limits indexes to 767 bytes. Exceeding these limits leads to errors.

Database Replication

Use MySQL’s built‑in backup and restore commands.

Copy data files directly to the target server (watch for file locks).

Employ third‑party synchronization tools (often the simplest choice).

Partitioning

For very large tables, define at least one partition early; adding partitions later can be difficult or impossible.

Slow Query Monitoring

Enable slow‑query logging to capture queries that exceed a defined execution time, making performance troubleshooting much easier.

Binlog

The binary log records all data‑changing statements, essential for point‑in‑time recovery and replication.

Other Views, Stored Procedures, Events

Advanced objects such as views, stored procedures, and scheduled events are often underused in projects, but understanding them can be valuable even if they’re not always needed.

Usable Tools

phpMyAdmin – convenient for remote GUI access, but clunky locally.

SQLyog – simple, though its UI feels dated.

Navicat – feature‑rich professional client.

Command‑line client – the most fundamental and powerful way to interact with MySQL.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

SQLmysqlReplicationtoolsDatabase Tips
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.