Creating New Databases and Tables with MySQL Administrator

From Techotopia
Revision as of 19:51, 27 September 2007 by Neil (Talk | contribs) (Creating New Tables)

Jump to: navigation, search

Unless a database already exists, very little can be done with MySQL until a database with at least one table has been created. Databases and tables can either be created using SQL commands (typically using the mysql tool) or using a grpahical administration tool such as MySQL Administrator. In this chapter we will cover the creation of databases and tables using MySQL Administrator. If you prefer to use SQL commands to perform these tasks refer to Creating Databases and Tables Using SQL Commands.

This chapter assumes you have an understanding of databases, tables and columns and have the MySQL Administrator installed, running and connected to a database server (see The MySQL Administrator Tool for details).

Creating a New Database

Once MySQL Administrator is running and connected to a database server, the first task is to create a new database. Begin by clicking on the Catalog option on the left hand side of the MySQL Administrator main window. The Catalog screen will then appear as follows:

Mysql admin catalog.jpg

The area in the bottom left hand corner of the screen entitled Schemata lists the databases currently under the control of the database server to which the administration client is currently connected. Selecting any existing entry in this list will list the tables contained within that database. In the above figure, a pre-existing database named PHPsampleDB is selected, which is shown to contain a single table named customer which contains 5 columns.

The columns in the table may be viewed and modified by selecting the desired table in the list and clicking the Edit Table button.

In order to create a new database, simply move the mouse pointer to any area of the Schemata list, click with the right hand mouse button and select Create Schemata from the popup menu. In the resulting Create Schema dialog, enter a name the new database. For the purposes of this tutorial we will use the name myDBase. Click on OK to initiate the schema creation.

If the new database is not currently selected in the Schemata list, select it and note that the view area now changes and shows no tables. The next task, therefore, is to create a table in our new database.

Creating New Tables

Although the MySQL Administrator makes the creation of tables extremely easy, an understanding of the fundamentals of database tables, columns and datatypes is recommended. If you are new to these concepts, it is worth first reading the Database Basics section of this book.

To begin the table creation process, first verify that the appropriate schema is selected in the Schemata section of the MySQL Administrator Catalogs page. With the correct schema selected, click on the Create Table button to display the Table Editor dialog shown in the following figure:

Mysql admin table editor.jpg