Structured Query Language (SQL) tutorial
Using SQL to Create a MySQL Database
We'll create a database called bus that contains details of bookings for our company XYZ Transport. The details we plan to store include customer names, dates and times, buses, destinations, customer and drivers' addresses, phone numbers etc.
Both the MySQL server and client need to be running for you to work with your database. The MySQL server started when you logged in to Windows because it was installed as a service. The MySQL client (called mysql from now on) has to be started. To do this:
- Select Start > MySQL > MySQL Server 4.1 > MySQL Command Line Client. The console window will appear.
- Enter your password (and all following commands) into this window. Once this is successfully entered, you are connected to the MySQL server.
After you connect to the server, you can create a database, as follows:
create database bus;
remembering that all SQL commands must end with a semi-colon (;). The MySQL server responds with something like
Query OK, 1 row affected (0.00 sec)
This means that you have successfully created the database.
Now let's see how many databases you have on your system.
- Type and run the following command.
The server responds with a list of databases:
| Database |
| bus |
| mysql |
| test |
3 rows in set (0.00 sec)
Here we have three databases, two created by MySQL during installation and our bus database.