OpenSourceVarsity

pdf icons

Creating a MySQL Database

MySQL is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases.

A database is a structured collection of data. A database could be anything from a simple shopping list to a picture gallery or vast amount of business information belonging to a corporate network. A database is an application commonly used to add, access and process data stored in a computer. Since computers are very good at handling large amounts of data effortlessly, databases play a pivotal role in computing, either as standalone utilities or as parts of other applications.

Creating a MySQL Database:

Invoke a DOS command window and login to MySQL as root:

<System prompt> mysql -u root p
Enter Password: <Enter the password for mysql root>

A welcome message is displayed as shown in Diagram 1:

diagram1 Diagram 1

Welcome message displayed by MySQL

The system prompt changes to: mysql>

At the mysql prompt type in:

mysql> CREATE DATABASE {databasename};

Example:
mysql> CREATE DATABASE SMS;

MySQL responds with something like:

Query OK, 1 row affected (0.00 sec) as shown in Diagram 2.

diagram2 Diagram 2

Creating database query in command prompt

This means that a database named SMS has been successfully created.

The SHOW DATABASES Command
Use the SHOW statement to find out what databases currently exist on the server.

mysql> SHOW DATABASES;

MySQL responds and displays a list of all the databases, which it controls as shown in Diagram 3.

diagram3 Diagram 3:

List of all databases using Show databases command

The list of databases is likely to be different on different computers, but the mysql, test and information_schema databases, which are created by default when MySQL was installed, are likely to be common across all.

The mysql database holds and describes user access privileges.

The test database provides a workspace for first time users to try things out in.

The information_schemadatabase (included in MySQL version 5.0.2 onwards) actually provides access to database, metadata.

The USE Command
Before working with data held within a table it is necessary to inform the MySQL db engine which database holds the tables. The USE command specifies which database the MySQL db engine should set as active.

Syntax:
USE<DatabaseName>;

NOTE: The USE command, like QUIT OR EXIT, does not require a semicolon.

NOTE: The USE statement must be written on a single line.

Example:
USE SMS;

Output:
Database changed

diagram4 Diagram 4

Using the use command at the command prompt

April 15, 2016
Design by Ivan Bayross and Meher Bala © 2017 All Rights Reserved
X