Unable to create database using MySql

Asked By 0 points N/A Posted on -
qa-featured

I am trying to create a MySql database. I've been encountering this issue which is beyond my knowledge. I'm new to MySql and this is my first attempt in creating a database. The error I've been encountering is written below. Please help me with this problem.

Error: 1007 SQLSTATE: HY000 (ER_DB_CREATE_EXISTS)
Message: Can't create database '%s'; database exists

SHARE
Best Answer by rominrom
Best Answer
Best Answer
Answered By 0 points N/A #86835

Unable to create database using MySql

qa-featured

Dear,

This is a SQL Error, it is a default message from database because you didn’t set an error reporting message, the Error message shows when you try to create a database by a name which already exists in the  MySQL Server.

The solution for this Error, first logout from the database and relogin to it and search if the name of the database which you would like to create exists, then change your database name which you would like to create. The Error message will not show.

Note: It will be good practice if you reset the database before checking whether the database exists on not.

Thanks.

Answered By 0 points N/A #86836

Unable to create database using MySql

qa-featured

This error message means that the database you tried to create is already created in the mysql server.So you can not create the database with the same name in the same server. To view the existing databases in the server, you can use the mysql command,

Show databases;

To fix the problem you have three choices:

•You can create a database with a different name
Create database if not exists database_name;

•You can rename the existing database
Rename database database_name to new_database_name;

•You can drop the existing database (make sure that the database is useless)
Drop database if exists database_name;

Answered By 0 points N/A #86837

Unable to create database using MySql

qa-featured

Hi,

Error: 1007 SQLSTATE: HY000 (ER_DB_CREATE_EXISTS)
Message: Can't create database '%s'; database exists

The above error message appears only because of the reason that the Database you wanted to create already exists, the solution to this problem is simple.

First Solution (Not recommended)

  1. You can drop the previous database "drop database [DatabaseName]". Be careful while using this statement as it will remove all of the tables inside that database, no information will be usable after this script runs inside the stated database.
  2. Again create the database by giving the same command or "create database [DatabaseName]"

Second Solution (Not Recommended)

  1. You can rename the database but that is also not recommended as it has some strange impact on DB schema.

Third Solution (Recommended)

  1. You can change the name of database you are creating the error will not be there after you will run the same command with new database name, you can use that new database name in the application without any hazards.

Login/Register to Answer

Related Questions