Creating a Database


Before you create a database, you need to address basic design issues:

  • What type of information do you want to include?

  • How many tables will you need to organize the information?

  • Which information will you designate as primary keys? (See Chapter 4.)

  • What types of relationships will there be among the pieces of information? (See Chapter 4.)

It's difficult to change your design later, so take the time to plan your database before you create it. For more information about database design, see "Database Design Basics," in the appendix of the "Beginner's Guide to Databases" in Dreamweaver Help (F1).

The travelclub database you'll create in this chapter is a SQL database with two tables that each contain four fields. The members table includes fields with basic information about the travel club members, such as id, first_name, last_name, and email. The flightprefs table includes fields with information about each member's preferences for flights, such as id, class, flight_time, and seat_location. The two tables are related via the id field, which is the primary key for both and uniquely identifies each member's information and flight preferences.

Tip

  • If you're using PHP to build Web applications, you'll need a SQL database so that you can create a database connection. You can't construct a SQL database directly in Dreamweaver, but you can use MySQL to create a database and database tables and then use Dreamweaver to create the database connection and queries.


To create a database using MySQL in Windows:

1.

From the Start menu, choose Control Panel > Administrative Tools. Double-click the Services Shortcut icon (Figure 5.1). The Services window appears.

Figure 5.1. Open the Services window by clicking the Services Shortcut icon in the Administrative Tools window.


2.

In the Services window, select MySQL (or whatever name you gave the MySQL service when you configured MySQL) and click the Start link to start the service (Figure 5.2). Close the Services window and the Administrative Tools window.

Figure 5.2. Select MySQL and click the Start link to start the MySQL service.


3.

From the Start menu, choose All Programs > MySQL > MySQL Server 4.1 > MySQL Command Line Client to open the MySQL Monitor.

If you haven't already installed MySQL on your computer, see Chapter 4 for more information on downloading and installing it.

4.

Enter your MySQL password.

A mysql prompt appears (Figure 5.3).

Figure 5.3. Once MySQL is successfully started, a mysql prompt appears in the MySQL Monitor.


5.

At the prompt, type CREATE DATABASE travelclub; and press Enter.

6.

At the prompt, type SHOW DATABASES; and press Enter.

A list of your MySQL databases appears (Figure 5.4). If the new database was created, the name should appear in the list. (The test and mysql databases are included in the MySQL installation.)

Figure 5.4. View the names of all your MySQL databases.


7.

At the prompt, type exit and press Enter to close the MySQL Monitor.

You're now ready to add tables and insert data into the database, which you'll learn to do in "To create database tables using MySQL," later in this chapter.

To create a database using MySQL on a Mac:

1.

From the Macintosh hard drive, select Applications > Utilities > Terminal. Double-click Terminal.

The Terminal window opens, and a prompt appears (Figure 5.5). The prompt includes [your computer name:~], followed by your Mac user name and the percent symbol (%).

Figure 5.5. Using the Terminal window in Mac OS X.


2.

At the prompt, type cd /usr/local/mysql and press Return.

The cd command changes the directory from your home directory (the directory with your Mac user name contained in the Users directory) to the mysql directory (Figure 5.6).

Figure 5.6. Change directories to access MySQL in a Terminal window.


3.

At the prompt, type sudo ./bin/mysqld_safe and press Return.

Password: appears in the Terminal window.

4.

Enter your Mac password and press Return.

The MySQL daemon starts (Figure 5.7). In Unix terminology, MySQL is called a daemon. It is equivalent to a Windows service.

Figure 5.7. Starting the MySQL daemon in Mac OS X.


5.

Press Control-Z, and then press Return.

Suspended appears in the Terminal window, followed by a prompt.

6.

At the prompt, type bg and press Return.

[1] sudo ./bin/mysqld_safe & appears in the Terminal window, followed by a prompt.

7.

At the prompt, type ./bin/mysql -u root -p and press Return.

Enter password: appears in the Terminal window.

8.

Enter your MySQL password and press Return.

MySQL starts and a mysql prompt appears (Figure 5.8).

Figure 5.8. Once MySQL is successfully started, a mysql prompt appears in the Terminal window.


If you haven't set a MySQL password, check your MySQL documentation and the MySQL online user's manual (http://dev.mysql.com/doc/mysql/en/index.html) for details on setting a MySQL password for the MySQL version and Mac OS X version you're using.

9.

At the prompt, type create database travelclub; and press Return.

10.

At the prompt, type show databases; and press Return to confirm that the database has been created.

A list of your MySQL databases appears (Figure 5.9). (The test and mysql databases are included in the MySQL installation.)

Figure 5.9. View the names of all the MySQL databases to confirm that you've created a new MySQL database.


11.

At the prompt, type exit and press Return to stop MySQL. At the following prompt, type exit and press Return to log out, and then quit Terminal. Close the Terminal window.

You can also stop MySQL by pressing Control-D at the prompt, and then, at the following prompt, pressing Control-D again to log out.

You're now ready to add tables and insert data into the database, which you'll learn to do in "To create database tables using MySQL," later in this chapter.

Tips

  • See the read-me file from the MySQL installation for additional configuration information about the installed version of MySQL.

  • When MySQL is running, you can create a connection to the new database in Dreamweaver. (See Chapter 4.)





Macromedia Dreamweaver 8 Advanced for Windows and Macintosh. Visual Quickpro Guide
Macromedia Dreamweaver 8 Advanced for Windows and Macintosh: Visual QuickPro Guide
ISBN: 0321384024
EAN: 2147483647
Year: 2004
Pages: 129
Authors: Lucinda Dykes

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net