MySQL
naming conventions
database design
SQL best practices
MySQL guidelines

Is there a naming convention for MySQL?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

MySQL does not enforce one official naming convention, but consistent naming is critical for maintainability, migration safety, and cross-team readability. Good conventions reduce ambiguity in schema design, simplify query writing, and prevent case-sensitivity issues across operating systems.

A practical convention should cover table names, column names, keys, indexes, constraints, and timestamp fields. The exact style can vary, but consistency is more important than preference.

Core Sections

1. Common baseline convention

Typical pragmatic rules:

  • use snake_case
  • use lowercase identifiers
  • use plural table names (or singular, but pick one)
  • use explicit foreign key columns like user_id
sql
1CREATE TABLE users (
2  id BIGINT PRIMARY KEY AUTO_INCREMENT,
3  email VARCHAR(255) NOT NULL,
4  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
5);
6
7CREATE TABLE orders (
8  id BIGINT PRIMARY KEY AUTO_INCREMENT,
9  user_id BIGINT NOT NULL,
10  total_cents INT NOT NULL,
11  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
12  CONSTRAINT fk_orders_user FOREIGN KEY (user_id) REFERENCES users(id)
13);

2. Name keys and indexes explicitly

Avoid anonymous engine-generated names.

sql
CREATE INDEX idx_orders_user_id ON orders(user_id);
CREATE UNIQUE INDEX uq_users_email ON users(email);

Explicit names improve migration diffs and troubleshooting.

3. Reserve suffix/prefix conventions

Useful patterns:

  • _id for FK and identifiers
  • _at for timestamps
  • is_ or has_ for booleans

Example: is_active, deleted_at, updated_at.

4. Avoid problematic naming patterns

  • reserved keywords (order, group) without escaping
  • mixed casing across environments
  • cryptic abbreviations without team glossary

5. Enforce with schema tooling

Use migration linters or review checklists so convention stays consistent across contributors.

Common Pitfalls

  • Mixing naming styles (camelCase, snake_case, uppercase) in one schema.
  • Letting tool-generated index/constraint names vary unpredictably.
  • Using reserved keywords and relying on backticks everywhere.
  • Ignoring case-sensitivity differences between local and production systems.
  • Choosing a convention but not enforcing it in migrations and reviews.

Summary

There is no single official MySQL naming convention, but strong consistency is essential. Choose a clear style, typically lowercase snake_case with explicit key/index names, and apply it everywhere. Name relationships predictably (*_id), avoid reserved-word friction, and enforce standards through code review or linting. Consistent naming pays off in query clarity, migration safety, and long-term schema evolution.

A practical way to keep this guidance useful in real projects is to convert it into an executable runbook rather than leaving it as one-time reading. A strong runbook lists exact prerequisites, expected versions, environment assumptions, and a short sequence of checks that confirm healthy behavior. It also records the first one or two failure signatures engineers are most likely to see and maps each signature to the next diagnostic step. This structure reduces ambiguity when incidents happen under time pressure and helps new contributors act with the same consistency as experienced maintainers.

It also helps to keep one minimal reproducible fixture in version control for this exact scenario. The fixture can be a tiny script, API call, YAML manifest, query, or test harness that demonstrates both expected success and a known failure mode. When dependencies, frameworks, or infrastructure versions change, that fixture becomes an early warning system for regressions. Instead of discovering breakage deep in production workflows, teams can run a focused check in minutes and isolate whether the problem is environmental drift, configuration mismatch, or logic change.

For long-term reliability, add one lightweight automated guardrail to CI that targets the most fragile point in the workflow. Good candidates include schema validation, deterministic unit tests, protocol compatibility checks, API contract tests, and startup smoke tests. Keep the guardrail narrow and fast so it runs on every change and produces actionable output when it fails. If the same issue class appears repeatedly, promote the manual troubleshooting step into automation. Over time, this shifts effort from reactive debugging to preventive quality control, and ensures the article stays aligned with how teams actually build, test, and operate software.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.