How to Change Database Name in MySQL?

MySQL does not support renaming a database directly with a single `RENAME DATABASE` command

Create a new database with the desired name:

`CREATE DATABASE new_database_name;`

Export the old database:

`mysqldump -u username -p old_database_name > old_database_name.sql`

Import the dump into the new database:

`mysql -u username -p new_database_name < old_database_name.sql`

Verify that all tables and data were copied correctly

Update application configuration files to use the new database name

If needed, remove the old database:

`DROP DATABASE old_database_name;`

Alternative method for small databases:

Rename each table individually after switching to the new database

Use `RENAME TABLE old_database.table_name TO new_database.table_name;` for each table

Recreate users, permissions, triggers, procedures, and events if they are not included in the dump

Test the application after the database name change

Suggested for You

Trending Today