On modern MySQL, rename a column with ALTER TABLE table_name RENAME COLUMN old_name TO new_name, then update every dependent consumer safely.
The statement may be metadata-only. The product migration is not. Application code, reports, views, triggers, generated columns, ETL jobs, and dashboards can all know the old name.
Table of contents
- Use the syntax supported by the server
- Inventory every dependency
- Use expand and contract for zero-downtime systems
- Plan locks, replication, and rollback
- Validate before cleanup
- How this fits the rest of the stack
- FAQ
Use the syntax supported by the server
MySQL 8 supports the clear RENAME COLUMN form. Older versions use CHANGE COLUMN, which requires repeating the complete column definition. Confirm the exact server version and current schema before generating the migration.
ALTER TABLE users
RENAME COLUMN displayname TO display_name;
-- Older MySQL syntax must repeat the type and attributes
ALTER TABLE users
CHANGE COLUMN displayname display_name VARCHAR(120) NOT NULL;
With CHANGE, omitting a default, collation, nullability rule, or other attribute can alter more than the name. Read SHOW CREATE TABLE and use migration tooling that preserves the definition.
Inventory every dependency
Search application queries, ORM models, migrations, views, stored routines, triggers, generated columns, scripts, analytics, exports, and documentation. Dynamic SQL and external reporting tools may not appear in the main repository.
Use query telemetry and database metadata to complement code search. Assign owners for important consumers and decide whether they can be updated atomically or need a compatibility window.
Use expand and contract for zero-downtime systems
When old and new application versions overlap, a direct rename can break one side. Add the new column, write both values, backfill in bounded batches, switch reads, validate, stop old writes, and remove the old column later.
Dual writes introduce consistency risk, so centralize them and monitor mismatches. Some teams use a compatibility view or application alias instead. Choose the simplest bridge that matches release and rollback requirements.
Plan locks, replication, and rollback
Even metadata operations need locks and can wait behind long transactions. Test the exact statement on a production-like schema, inspect supported online DDL behavior, set a sensible lock timeout, and schedule around known long-running work.
Monitor replica lag, error rate, query latency, and connection pools during rollout. A reverse rename is not enough rollback if newer application writes already depend on the new schema. Define the code and data rollback together.
Validate before cleanup
Verify schema, row counts, null rates, backfill equality, read and write paths, reports, jobs, and backups. Keep the compatibility period long enough to cover infrequent consumers such as monthly exports.
Only remove the old column after telemetry shows it is unused and the rollback window has closed. Schema cleanup is valuable; premature cleanup is just an outage with excellent naming consistency.
How this fits the rest of the stack
Before a migration changes database size, replicas, or service rollout, compare the whole stack in the RunxBuild hosting calculator. Then coordinate the application and database deployment through the RunxBuild dashboard with logs close at hand.
Useful related references:
- MySQL to MySQL: Migrating a Database Between Servers
- MySQL Pivot: There Is No PIVOT, So Here Is What to Do Instead
- mysql -u root -p: What the Flags Mean and Why You Should Stop Using Root
- Databases on RunxBuild
FAQ
What is the MySQL 8 syntax to rename a column?
Use ALTER TABLE table_name RENAME COLUMN old_name TO new_name. Verify compatibility with the exact server version.
How do I rename a column in older MySQL?
Use CHANGE COLUMN old_name new_name full_column_definition, repeating the complete type and attributes carefully.
Does renaming a column delete data?
A correct rename preserves values, but mistakes in legacy CHANGE definitions or dependent applications can still cause damage. Test and back up first.
Is a column rename zero downtime?
Not automatically. Locks may be brief, but overlapping application versions can break. Use an expand-and-contract rollout when compatibility is required.
Do indexes follow a renamed column?
The database updates direct column metadata, but verify indexes, generated expressions, views, triggers, application queries, and external consumers on your version and schema.