MySQL CREATE DATABASE Statement

MySQL | CREATE DATABASE: Learn about the MySQL CREATE DATABASE Statement, with its explanation, syntax, and query examples.
Submitted by Apurva Mathur, on September 03, 2022

What is Database?

As we have discussed earlier, a database is a collection of data, we can assume it as a hard copy file but when it comes to manage the data electronically then the database comes into the picture.

You can consider a database is like a folder where you'll store all your tables and under your tables, you'll have your rows and column

DATABSE Sample

How to Create a MySQL Database?

First, we'll see the traditional way of creating a database i.e. by writing a SQL query in the MySQL command line client.

If you are a beginner, then I strongly suggest that work on MySQL command line client as this is the best way to learn how queries work when we fire them.

CREATE DATABASE Statement Syntax

Here is the syntax to create a database.

CREATE DATABASE DATABASE_NAME;

Here, DATABASE_NAME can be anything but while writing the DATABASE_NAME kindly keep the following things in your mind,

  • Always start your database name with an alphabet.
  • Do not start your name with any space, numeric value, or symbols.
  • Spaces are allowed in the database but only between the characters.
  • It is always considered a good practice when you use underscore _ in place of space. For example, Student_Details looks good than Student Details.
  • Database names are case sensitive which means if you have written your database name in camel case so whenever you are using the database name in a query you have to write the name in camel case only, else it will show you an error.

Now we'll see this in the MYSQL command line client.

MySQL CREATE DATABASE (1)

As you can see 1 row is affected which means our database named as the student has been made.

Now, the question arises of how see our database, so for this, we have to write SHOW DATABASES command.

MySQL SHOW DATABASES Statement

This command/statement is used to get a list of all databases of a MySQL server host.

SHOW DATABASES;

Write this command and press Enter. After executing this command. We will see all the databases.

MySQL CREATE DATABASE (2)

This is the list of all the databases.

Now we'll see a shortcut method to create a database, and for this, we'll use MySQL Workbench.

MySQL Workbench - Creating and Showing Databases

Step 1: Open MySQL Workbench, and enter your password.

MySQL Create Database on Workbench (1)

You'll see this front-end when you'll open the MySQL workbench.

Step 2: Now right-click under the SCEHAMS section and click on create schemas. (In workbench database is commonly called schema)

MySQL Create Database on Workbench (2)

Step 3: After clicking on create schemas we'll simply write the database name and apply that schema.

MySQL Create Database on Workbench (3)

Here I've kept my new_student_database as my database/schema name you can keep anything.

Step 4: After applying this, you'll see the following screen,

MySQL Create Database on Workbench (4)

Again just click on apply.

Step 5: Our database is created now.

MySQL Create Database on Workbench (5)



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.