Creating First Database-tutorial
Now that you understand what a Database, Table, Rows, and Columns are it is time to actually create your first database.
Think of this as creating a folder on your computer where all your tables (files) will live.
Let us create one called SchoolDB
Output
You can see SchoolDB is successfully created
This tells MySQL
Hey, i will be working inside this database from now on!
Now all your upcoming commands will affect SchoolDB
What is a Database in SQL?
A database is a container that stores and organizes your data into tables.
Each database can have one or more tables and each table holds specific types of information (like Students, Products, Orders, etc.).
In SQL, before you store any data, you need to create a database to keep everything organized.
Step 1: Open MySQL
Creating a Database in MySQL
Step 1: Open MySQL
You can open MySQL in two ways:
- Using MySQL Workbench (GUI) - a visual tool.
- Using MySQL Command-Line Interface (CLI) - text-based terminal.
(Both methods do the same thing. Choose whichever you prefer.)
Step 2: Write the SQL Command
To create a database, use the simple SQL command:
CREATE DATABASE database_name;
Let us create one called SchoolDB
CREATE DATABASE SchoolDB;
Explanation
- CREATE DATABASE - tells MySQL to make a new database.
- SchoolDB - name of your database (you can choose any name, but avoid spaces and special characters).
Step 3: Check if the Database is Created
To see a list of all databases:
SHOW DATABASES;
Output
+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || SchoolDB |+--------------------+
You can see SchoolDB is successfully created
Step 4: Select Your Database
Before you start creating tables or adding data, you need to select the database you want to work in.
USE SchoolDB;
This tells MySQL
Hey, i will be working inside this database from now on!
Now all your upcoming commands will affect SchoolDB
Two Minute Drill
- CREATE DATABASE - Creates a new database
- SHOW DATABASE - Lists all databases
- USE database_name - Selects the database to work with
- Database = Container that holds multiple tables
- Every SQL Project starts by creating a database