Tutorial on how to create database in MySQL for beginners.
MySQL is a programming language which acts as an interface between the user and the database. This tutorial helps you to create an Oracle Database using the MySQL code. MySQL commands have to be entered through a command prompt and there is no graphical visual interface. Follow the below steps in the tutorial on how to create a database in MySQL.
Syntax for creating a Database:
CREATE DATABASE <DATABASENAME>;
Follow the below steps to create the database called as "Employees".
Step 1: Display all available databases:
In the MySQL command prompt, enter the command SHOW DATABASES;
It lists all the databases you have stored.
Step 2: Create the Database:
From the MySQL command line, enter the command CREATE DATABASE Employees;
Database Name cannot include spaces.
Semicolon ";" is a must at the end of the MySQL command.
Step 3: Display the databases again:
Now you could see the database "Employees" in the list.
Step 4: Select your database to edit it:
Enter the command USE Employees;
You can see the message "Database changed".
Now your active database is Employees.
Step 5: Create a table in the database Employees:
A database can contain one or more tables.
CREATE TABLE Employee_Details (emp_id INT, Name CHAR(25), Sex CHAR(10), Age INT(9));.
This will create a table named "Employee_Details" with three fields: emp_id, Name and Age.
The INT command will make the emp_id field contain only numbers (integers).
The CHAR (characters) command will make the name field contain only characters.
The number next to the commands indicates how many characters or integers can fit in the field.
Step 6: Enter values in the table.
INSERT INTO Employee_Details (emp_id, Name, Sex, Age) VALUES (2345, Abella, F, 34);
Step 7: You can enter more rows in the table.
You can create multiple entries using a single command.
INSERT INTO Employee_Details (emp_id, Name, Sex, Age) VALUES (2346, Santa, F, 47), (2347, Grader, M, 26), (2348, Ritula, F, 32);
Step 8: Retrieve data from your Database.
Use SELECT statement to query values from tables in your database.
SELECT * FROM Employee_Details;
This will return all the rows in your table as "*" means "all".
Step 9: Drop your Database.
Below is the MySQL statement to drop a database.
DROP DATBASE Employees;
This will completely drop (delete) the database "Employees" with all its tables.