DbSchema | MySQL - How to rename a Database
In this article, I’m going to show you how to create a mysql dump and use it to rename your mysql database.
First of all, open the start bar, write cmd and run it as administrator by right-clicking on it. After that, navigate to the MySQL Server bin folder.
Once there, create a mysql dump:
mysqldump -u username -p -R database_name > dbname.sql;
- Replace the username, password and dbname;
- Replace the name of the dump file (.sql).
Now, create a new database with the new name:
mysqladmin -u username -p create new_dbname;
Make sure that this name is not already in use. Enter the mysql shell with __mysql.exe -u root -p and execute __SHOW DATABASES
. To check if the database is created, use this command. To exit the shell, type __exit`.
Then, you have to import the dump in the newly created database:
mysql –u username –p new_dbname < dbname.sql;
The last step is to delete the old database:
mysqladmin -u username –p drop dbname;
After creating the new database, you may have to grant the privileges back to some users. Read this article to see how.