0

I created a fresh database in phpmyadmin which does not contain any tables yet since its fresh, however I accidentally made a typo. How can I rename the database?

If this happens to me I usually just execute the SQL command:

DROP DATABASE dbname;

and create another database. But is it possible to rename it? I was already searching SO but found nothing helpful.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Black
  • 18,150
  • 39
  • 158
  • 271
  • Possible duplicate of [Rename mysql database?](https://stackoverflow.com/questions/13643802/rename-mysql-database) – waka Aug 18 '17 at 12:28
  • Possible duplicate of [How do I quickly rename a MySQL database (change schema name)?](https://stackoverflow.com/questions/67093/how-do-i-quickly-rename-a-mysql-database-change-schema-name) – tima Aug 18 '17 at 12:29

4 Answers4

1

I found two possible solutions.

  1. Rename it via the phpmyadmin backend UI (preferable):

enter image description here

enter image description here

  1. Or just execute this SQL (only use it if the database is fresh and does not contain any data yet, otherwise it will be lost!)

    CREATE DATABASE newname;

    DROP DATABASE oldname;

Black
  • 18,150
  • 39
  • 158
  • 271
0
ALTER DATABASE oldName MODIFY NAME = newName
DotNetLover
  • 229
  • 1
  • 4
  • 11
0

I don't think you can do this. I think you'll need to dump that database, create the newly named one and then import the dump.

If this is a live system you'll need to take it down. If you cannot, then you will need to setup replication from this database to the new one.

If you want to see the commands try this link, Rename MySQL database

knight007
  • 55
  • 7
0

Try using an aux temporary db (as copy of the original)

$ mysqldump dbname > dbname_dump.sql //create a backup
$ mysqladmin create dbname_new //create your new db with desired name
$ mysql dbname_new < dbname_dump.sql //restore the backup to the new one
$ mysql drop database dbname; //drop old one
aaron0207
  • 2,293
  • 1
  • 17
  • 24