3.2. Building a Database

A database has two parts: a structure to hold the data and the data itself. In the following sections, we explain how to create the database structure. First, you create an empty database with no structure at all, and then you add tables to it.

When you create a database, you create a new subdirectory in your data directory with the database name that you assign. Files are then added to this subdirectory later, when you add tables to the database. The data directory is usually a subdirectory in the directory where MySQL is installed. You can set up a different directory as the data directory by adding a statement in the MySQL configuration file, my.cnf, in the following format:

datadir=c:/xampp/mysql/data

You can add this statement to the configuration file or change the statement that's already there.

You can create the database by using SQL queries, as described in Chapter 1 of this minibook. You can also create the database by using features of phpMyAdmin. To create a database, you must use a MySQL account that has permission to create, alter, and drop databases and tables. See Chapter 2 in this minibook for more on MySQL accounts.

3.2.1. Creating a new database

Your first step in creating a new database is to create an empty database, giving it a name. Your database name can be up to 64 characters long. You can use most letter, numbers, and punctuation, with a few exceptions. In general, you can't use characters that are illegal in directory names ...

Get PHP & MySQL® Web Development All-in-One Desk Reference for Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.