Database

A database is used to store the collection of records  in the form of tables, rows, columns, and indexes to find the relevant information frequently. The creation of database can be made using a command line or an IDE – MySQL workbench. The command used to create a database is as follow

Syntax: -

CREATE DATABASE database_name;

Example: - 

CREATE DATABASE equipment;

Figure 1.1 : – Creating Database

Select Database

Selecting Database is one thing that we do in choosing the database that we are trying to work on. This option is used in the case that there are multiple or many database then we like to work with specific database. Once the selection is made, it is easier to work with the database components and MsQL query statement since we are referring specifically to the selected Database. The application of selecting database is as following using the command

Syntax: - 
USE databaseName;

Example: -
USE equipment;

Figure 1.2 : – Selecting Database

Show Database

The next step to do once. the database is created, is to make sure that the database is in the list of database. inorder to do that, we apply the following command

Syntax: - 
SHOW {DATABASE | SCHEMA)

Example : -
SHOW DATABASES;
SHOW SCHEMAS;

Figure 1.3: – Show existing Database

Drop Database

This action is used delete the database along with all the tables, indexes, and constraints permanently.  Taking this kind of action requires a lot of certainty since once you drop or remove database, the database is no more replacable and it will permanently delete from MySql..

In-order to Drop a database, the following command line statement will be used

Syntax: - 
DROP {DATABASE | SCHEMA} [IF EXISTS] db_name

Example:- 
DROP DATABASE equipment;
DROP SHEMA equipment;

Figure 1.4: – Dropping Database

Copy Database

This is one of the common command that is used to copy the original database into a new database . The main reason is incase of accidentally loose of our database or failure, it is easier to get it back. In addition to if in case we want to do a major change on the database, it is more advisable to keep the copy of the original database not to loose what we had before.

Therefore to start the cloning or copying of a database, please prepare first another database which is serving as a destination to copy the original database. The command used mysqldump and the aoplication of the command is as follow

//copying the Origin DB to local file
mysqldump -u root -p sourceDb > D:\Database_backup\original.sql  

form a local file to destination database
mysql -u root -p destinations < D:\Database_backup\original.sql;  
Scroll to Top