Open Source Tutorials - Open Source Training
Open source training & tutorials from experienced, passionate people
chrome icon firefox icon ie icon opera icon safari icon Sings in these Browsers
A- A A+

By A Web Design

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.gif
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.gif
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.gif
Diagram 3: List of all databases usingShow 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 mysqldatabase holds and describes user access privileges.

The testdatabase 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.gif
Diagram 4: Usinguse’ command on command prompt

OSV Newsletter


Receive HTML?

NOTE: To prevent subscription to the OSV newsletter, uncheck the checkbox above.
Guest Blog for OSV
Free Ebook Download
LinkShare_180x150
Artisteer - DNN Skin Generator
Tapestry Theme - A Tumblog-Style Theme for Wordpress