Your first MySQL Database

Hoping that you've successfully installed the MySQL distribution onto your system, let's start creating your first MySQL database. Last month we used Microsoft Access to create a simple Clients database which contained two tables -- we'll recreate that pleasantly simple structure here in MySQL. Although this is a simple example, it should lay the groundwork for any other relational database you wish to create and manage in MySQL.

To recap from last month, let's look once again at the Clients database, and the two tables it consists of:

Clients database with two tables.
billing: a sample database table
ClientName ClientEmail Invoice Total Paid
Loganberry Inc. 099050101 50.00 Yes
Smart Corp. 099050102 450.00  
Arlene Von Smitten 099060101 500.00 Yes
Sanford & Son 099060102 75.00  
B. Gates 099060103 25000.00  
Fanny Farmer 099070101 55.50 Yes
invoices: a sample database table
Invoice Hours Rate
099050101 1 50
099050102 9 50
099060101 12.5 40
099060102 1 75
099060103 50 500
099070101 3.7 15

We'll assume that the data for these tables now resides in tab-delimited text files; in other words, the text file containing the data for billing would look like:

Loganberry Inc.  099050101  50.00  1

As summarized earlier, we need to first establish this database in MySQL and create the skeletal structure for the tables -- then we can import the raw data.

Step 1: Create a new database using mysqladmin.

/path/to/mysql/bin/mysqladmin -u root -p rootpassword create Clients

By default, the MySQL server will create a subdirectory for the new database, Clients, in mysql/data. If you would like to store your databases somewhere other than the MySQL installation path, you need to start mysqld with the --datadir parameter; simply execute mysqld --help on a command line to view usage details.