Chapter 27. Creating Databases

27.1 Introduction

Each table that is created is stored in a database. During MySQL installation, two databases are created automatically and used to store the catalog tables. We do not recommend adding your own tables to these databases. It is better to create new databases for this by using the CREATE DATABASE statement. Section 4.4 contains an example of this statement. In this relatively short chapter, we deal with this statement at great length.

27.2 Databases and the Catalog

MySQL stores information on databases in the catalog table called INFORMATION_SCHEMA.

Example 27.1: Show the names of all databases.

SELECT   SCHEMA_NAMEFROM     INFORMATION_SCHEMA.SCHEMATA

The result is:

SCHEMA_NAME------------------ ...

Get SQL for MySQL Developers: A Comprehensive Tutorial and Reference 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.