How to change the database name in MySQL?

Sometimes we need to change or rename the database name because of its non-meaningful name. To rename the database name, we need first to create a new database into the MySQL server. Next, MySQL provides the mysqldump shell command to create a dumped copy of the selected database and then import all the data into the newly created database. The following is the syntax of using mysqldump command:

  1. mysqldump -u username -p “password” -R oldDbName > oldDbName.sql  

Now, use the below command to import the data into the newly created database:

  1. mysql -u username -p”password” newDbName < oldDbName.sql