Skip to content

Computer Science · Ch 9 — Structured Query Language (SQL)

CREATE Database

9.4.1

CREATE Database

To create a new database in MySQL, you use the CREATE DATABASE statement. The syntax is straightforward:

CREATE DATABASE databasename;

For example, to create a database called StudentAttendance, you would type:

mysql> CREATE DATABASE StudentAttendance;
Query OK, 1 row affected (0.02 sec)

The message "Query OK, 1 row affected" confirms that the database has been created successfully.

Watch out

Case sensitivity of database names

In a Linux environment, database and table names are case-sensitive. In Windows, they are not. As a good practice, always write database and table names in the same letter case you used when creating them — this avoids confusion if you later switch operating systems.

A DBMS can manage multiple databases on one computer. So after creating a database, you need to select it before you can work with it. To see which databases already exist, use:

mysql> SHOW DATABASES;

This lists all databases on the server. From that list, you choose the one you want to use with the USE statement:

mysql> USE StudentAttendance;
Database changed

The message "Database changed" tells you that you are now working inside the StudentAttendance database.

Initially, a newly created database is empty — it contains no tables. You can verify this with:

mysql> SHOW TABLES;
Empty set (0.06 sec)
``` …