How to Rename a Database in MySQL

In this article, we will see how to Rename a Database in MySQL. In previous versions of MySQL, RENAME DATABASE is used to rename database. From all newer versions, RENAME DATABASE has been removed to avoid security risks.
We can rename database in MySQL using dump and restore process.

Steps to Rename a Database in MySQL:

mysqldump syntax:

mysqldump –u [UserName] –p[Password] –R [DB_Name] > [DB_Name].sql

Replace [UserName] and [Password] with the actual credentials for the database, and replace [DB_Name] with the exact name of the database you’re changing. There should be no space between -p and the password. The -R flag indicates that the dump file should retain all stored procedures and functions.

1) Create dump using mysqldump tool. Here r2schools is the database name.

mysqldump -u root -p -R r2schools > r2schools.sql

Continue reading How to Rename a Database in MySQL