Jump to content

PHP and MySQL Programming/Creating a Database

From Wikibooks, open books for an open world

Introduction

[edit | edit source]

MySQL is a relational database. In a relational database, data is stored as a collection of fields called a row. Like fields, rows are in turn collectively stored as a table. Tables are stored collectively in a database. One MySQL server can store multiple databases, and have users who have various rights to each database.

Nowadays, MySQL is one of the most popular relational databases among others as it is simple, free (open source), easy to maintain, and cost-effective.

In order to store data into MySQL, we will need to prepare a space in MySQL for a database.

SQL Code

[edit | edit source]

The code for creating such a database in SQL (Structured Query Language) is a simple query:

mysql> CREATE DATABASE `database_name`;

(Without the ' ' single quotes around the database name)

Using the Database

[edit | edit source]

After a database has been created, you have to tell MySQL that to make it the active database before you can start running further queries on it. You do this as follows:

mysql> USE `database_name`;