Database Queries

Written by

Soumya Shaw

Okay, that was all boring and Theoretical stuff before and it’s time to really get into the syntax part and get our hands dirty.

We will start off with the basic screen that will appear in front of you, the moment you start the Command Line Client.

As explained, the initial response required after MySQL startup will be entering the Password and verifying the identity then eventually, you can see a “mysql>” symbol that keeps on taking a blinking space for your response.

This indicates the successful onset of the MySQL and you can start working now.

As you have enough knowledge about a Database now, let’s see how to practically create it.

Showing Database:

Step 1: Type show databases;

This will show you all the databases that are already there in your MySQL i.e. preinstalled in your system and should look similar to the below-shown image.

Note: Don’t play around with the specific two databases that are ‘information_schema’ and ‘peformance_schema’, as those databases contain very important information regarding the software and may lead to crashing.

Creating a Database:

Once you’ve seen the database list and verified if your particular database is there or not, you can either choose to create one or select one.

Hence, let’s assume you need to create a database so,

Step 2: Use the command ‘create database <database_name>;’ to create a new database of that particular name. The same is done by naming the database studymite.

Step 3: Once again you can check if the database is created or not, and evidently there is a new database now named studymite now!

Selecting & Using Database:

Step 4: Type ‘use <database_name>;’ and press Enter. The following message will appear.

Deleting Database:

Step 5: Use the command ‘drop database <database_name;>’ to delete the database.

Let’s check once more if our command succeeded.

Note: MySQL tries to prompt the mistake and its correction everywhere possible but still try to be perfect before finishing the command.

I have seen people always forgetting to add the semicolon symbol (;) after the command so double check the semicolon as the command will not terminate even after pressing ‘Enter’ and will go to next line without giving you any clue.

Let me show you one example.

Database Queries