Create MySQL Database

creating MySQL database

a database is a container of data.in mysql, a database is a collection of objects that are used to store and manipulate data such as tables, database views, triggers, stored procedures, etc.

the create database statement is used to create a database.

syntax :

           create database         [if not exists]      database_name ;

the if not exists is an optional element of the statement.

the if not exists statement prevents you from an error of creating a new database that already exists in the database server.

you can't have two database with the same name in a mysql database server.

the database name cannot contain spaces, slashes, or periods.

the MySQL create database <database_name> command must end with semicolon (;),If you forgot to include the semicolon, then you can put just ";" on the next line to process the previouse command.


MySQL Create Database Command

the following mysql statement creates a database called "company" :

                   create database      company  ;
                   create database      [if not exists]    user_data  ;

in the second case, the use of the if not exists clause force mysql to run the command only if the database doesn't exist,result in more graceful handling and no error output.


what is database.

the database is an organized collection of data.Database management systems(DBMS) are specially designed applications that interact with the user, other applications, and the database itself to capture and analyze data.Each database has one or more distinct APIs for creating, accessing, managing, searching, and replicating the data it holds.


MySQL show database Command

if you want to show your database which you create then you use the MySQL show databases command

   mysql> show databases;

output

 
                         +-----------------------+
                         |Database                    |  
                         +-----------------------+
                         |company                     |  
                         | user_data                   |
                         +-----------------------+
                         2 rows in set (0.00 sec)

in the above output the company and user_data are name of databases.

after you've selected a database, you can view available tables in it with the show tables command

mysql> show tables;

note - when no tables available in database then the show tables command donot show any result.