A Mysql databases server contains many databases. Each databases consists of one or more tables. A table is made up of columns and rows

Creating Databases

'CREATE DATABASE' command is used to create a new database. the general form is 

  1. CREATE DATABASE  databasename;
  2. CREATE DATABASE IF NOT EXISTS databasename;
where
CREATE,DATABASE, IF NOT EXISTS - Keywords
databasename - name of the database to be created. First one creates a new database. Second one creates only if database does not exist.

Example
  1. mysql > CREATE DATABASE  Polytechnic;
After successful execution, a message 'Query OK,
1 row affected will be displayed.

2 mysql > CREATE DATABASE IF NOT EXISTS poliytechnic;
 create if 'politechnics' database does not exist.

Dropping databases
            'DROP DATABASE' command is used to drop the existing database. The general form is 
         
  •             DROP DATABASE databasename;
  • DROPDATABASE IF EXISTS databasename;
where
 DROP, DATABASE, IF EXISTS - KEYWORDS
     databasename - name of database already existing.
Example
1) mysql > DROP DATABASE  politechnic;
after successful execution, 'Query ok , 0rows affected'
message is displayed i.e. politechnic i.e. politechnic database is deleted.
2) mysql > DROP DATABASE IF EXISTS politechnic;
Drops the database 'politechnic' only if the database exists.

Selecting Databases
    To set default database, 'USE' command is used.
Syntex
            USE databasename;

Example

            To set  'politechnic' database as the default database, 
        mysql > USE politechnic;
Database changed message is displayed after execution of the above command.
    To show the default database, 'select DATABASE commend is used.

 Syntex 
                SELECT DATABASE();
Example
Assume that the default current database is 'polytechnic'. Now
    mysql> SELECT DATABASE();
    Output is 
         ---------------------------------
        ---DATABASE()----------------

        politechnic


showing Database
            'SHOW DATABASES' commend is used to list all the existing database in the server.
    Syntex 
                    SHOW DATABASE;

Example

            musql > SHOW DATABASES;

                            database
                    information_schema
                    mysql    
                    performance_schema
                    test
                    politechnic

     The database 'mysql', 'infromation_schema' and performance_schema are system database used internally by MYSQL. A 'test' database is provided during installinon for your testing . 'polytechnic' is the user create database.

20 sec