Previous Next  

Mysql - Create Database

To create a database in MySQL, you can use the CREATE DATABASE statement followed by the name you want to give to your database. Here's the basic syntax:

CREATE DATABASE database_name;

For example, to create a database named `mydatabase`, you would use the following SQL statement:

CREATE DATABASE mydatabase;

If the database is created successfully, MySQL will return a message indicating that the operation was successful. You can then use this database to create tables and store data.

IF NOT EXISTS clause

If you try to create a database with an existing name, an error will be generated like below

ERROR 1007 (HY000): Can't create database 'mydatabase';

If you use the `IF NOT EXISTS` clause along with the `CREATE` statement as shown below a new database will be created and if a database with the given name, already exists the query will be ignored.

CREATE DATABASE IF NOT EXISTS mydatabase

  Previous Next  

Aspirant's Home is an innovative educational and career development platform designed to empower individuals in achieving their academic and professional aspirations.
Terms of Use   About Us   Privacy Policy