Mysql rename database command line

Mysql rename database command line

Blog Bustle 21/02/2020

Sometimes we have to change the database name according to our need and we do not have any other option. Mysql rename database command line was used to change the database name in mysql older versions but it has been removed from mysql latest versions because of security reasons.

Mysql rename database command line syntax

rename database old_database_name to new_database_name;

This mysql rename database command line no longer works.

So how can we rename mysql database?

Rename mysql database steps:

Step 1: export database whom you want to rename

Step 2: create database with new_database_name

Step 3: import database backup file into new database

This is the safe mysql rename database method.

For example, i want to change the name of student database. So first we export student database

Export mysql database command line syntax

mysqldump -u [username] -p [password] [database_name] > [dump_file_name.sql]

i am using local server. In my case, export mysql database command line will be

mysqldump -u root -p student > d:\student.sql

We know we use mysqldump tool for export database. In this export mysql database command line username is root, password is empty, database is student and dump file name is student.sql

I wanted to rename student database by college database. So i am going to create college database.

Create database syntax will be

create database college;

so we have taken student database backup and created college database. Our next step is to import student database backup file into college database.

Import database mysql command line syntax

mysql -u [username] -p [password] [database_name] < [dump_file_name.sql]

In my case, import mysql database command line will be

mysql -u root -p college < d:\student.sql

rename mysql database command line

So by following these simple steps we can easily change the database name.

Rename mysql database method is very useful when we have to change the database name according to our need or we create wrong database by mistake.

Other important links

Copy database in mysql

Import database in mysql

Export database in mysql

Mysql create database

Mysql rename database command line searches:

Tags: #mysql