Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the database name using MySQL? [duplicate]

Tags:

mysql

How can I change the database name of my database?

I tried to use the rename database command, but on the documents about it it is said that it is dangerous to use. Then what should I need to do to rename my database name?

For example, if I want to rename my database to this.

database1 -> database2?
like image 726
Jerielle Avatar asked Sep 04 '25 16:09

Jerielle


1 Answers

Follow bellow steps:

shell> mysqldump -hlocalhost -uroot -p  database1  > dump.sql

mysql> CREATE DATABASE database2;

shell> mysql -hlocalhost -uroot -p database2 < dump.sql

If you want to drop database1 otherwise leave it.

mysql> DROP DATABASE database1;

Note : shell> denote command prompt and mysql> denote mysql prompt.

like image 150
Nanhe Kumar Avatar answered Sep 07 '25 06:09

Nanhe Kumar