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.

2

4 Answers 4

2

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;

Sign up to request clarification or add additional context in comments.

Comments

0
ALTER DATABASE oldName MODIFY NAME = newName

2 Comments

I get Error in SQL Syntax
EXEC sp_renamedb 'oldName', 'newName'
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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.