How do I rename a MySQL database (change schema name)?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
MySQL does not support a simple RENAME DATABASE command in modern versions, so “renaming a schema” is always a migration workflow. The safest pattern is to create a new schema, move or import objects, verify, then drop the old schema. The right method depends on downtime tolerance, object count, and whether cross-schema object references exist.
Why There Is No Direct Rename Command
Historically, direct database rename caused too many integrity and metadata risks across storage engines and server versions. Today, MySQL expects administrators to use explicit migration steps instead of one destructive shortcut. That means your rename process should be planned like a controlled cutover.
Method 1: Dump and Restore
For many environments, dump-and-restore is the clearest and safest approach.
1) Create target schema
2) Export old schema
3) Import into new schema
4) Validate counts and key objects
5) Re-point app and remove old schema after validation
This method is straightforward and preserves object definitions when dump options are set correctly.
Method 2: Move Tables With RENAME TABLE
If you need a faster in-server move for tables, create new schema and rename table by table.
This is fast for table data movement, but there are caveats:
- Views, routines, and events are not automatically migrated by table renames.
- Stored routine definitions can contain schema-qualified references that still point to old schema.
- Foreign keys and view dependencies need careful validation.
For complex databases, dump-and-restore is often less error-prone.
Generate Rename Statements Automatically
For large table sets, generate SQL safely from metadata.
Review generated statements before execution. Do not run metadata-generated SQL blindly in production.
Privileges and Application Cutover
Schema rename workflows usually require privilege updates.
Then update application configuration:
- connection string schema name.
- migration tool config.
- reporting jobs and ETL scripts.
A clean cutover includes read and write smoke tests before deleting old schema.
Downtime and Consistency Strategy
If writes continue during migration, old and new schemas diverge. Choose one strategy:
- short maintenance window and full cutover.
- replication-style dual-write logic during transition.
- read-only freeze before final export.
For most teams, planned maintenance window is simplest and safest.
Verification Checklist
Before final drop of old schema:
- Table counts match expected values.
- Critical queries run from app against new schema.
- Routines, triggers, and events exist and compile.
- Privileges and monitoring dashboards are updated.
- Backup exists for rollback.
Keeping this checklist explicit avoids irreversible cleanup mistakes.
Common Pitfalls
A common pitfall is moving tables and assuming routines and views moved automatically. Another issue is forgetting schema-qualified references inside SQL code, which still point to the old schema after migration. Teams also sometimes drop old schema before full application verification, which removes rollback options. Privilege mismatches are frequent when new schema grants are incomplete. Finally, large migrations without a downtime or consistency plan can lead to data drift between old and new schemas.
Summary
- MySQL schema rename is a migration process, not a single command.
- Dump-and-restore is usually the safest default for full object coverage.
RENAME TABLEcan be fast but does not migrate all object types.- Update privileges and application config as part of cutover.
- Verify thoroughly before dropping the old schema.

