MySQL is a relational database management system, Database is organized data into more than one table. MySQL is a database system used for web application and its run on the server. The MySQL database is reliable, fast, easy to use. Mysql is a programming language used to create, insert, update, and extract data from the relational database (RDMS).
MySQL Create Database, Table, and Data Types
In this tutorial, we will learn how to create a database Mysql. There are multiple ways to create a database MySQL but in this tutorial, we will learn the below 3 ways.
By executing a SQL script/Query
By using Command line
By using the phpMyAdmin user interface
Table of Contents
Create database MySQL
Removing Databases (DROP DATABASE [IF EXISTS])
1. Create database MySQL
We need to write the CREATE DATABASE command to create a database MySQL. CREATE DATABASE is a SQL command which is used to create a database.
Now we will create a database named “testdemo” by executing the below SQL command line.
CREATE DATABASE testdemo;
Or you can also create a database by using the phpMyAdmin below the user interface. In this interface, just you need to simply enter the database name in the text field and submit. After submitting your database has been created in MySQL.
IF NOT EXISTS
The IF NOT EXISTS is an optional clause of the SQL statement. The IF NOT EXISTS clause statement prevents to check the existence of a database by making a new database that already exists in the database server. You can’t create 2 databases with identical names in a MySQL database server.
CREATE DATABASE IF NOT EXISTS testdemo;
SHOW DATABASES statement will show the list of all the databases in the MySQL database server. You can check the database that you are createdon the MySQL server by executing the SHOW DATABASES statement on the MySQL database server.
DROP DATABASE (Removing Databases) [IF EXISTS]
If we want to delete the DATABASE so we need to execute the following command on the database server. The IF EXISTS is an optional clause of the statement prevents to check a database before removing a database that does not exist in the database server.
DROP DATABASE [IF EXISTS] testdemo
A collation is a set of rules that defines examine and sort character strings. Every collation in MySQL belongs to a single character set. Each character set has a minimum of one collation, and most have two or more collations.
SHOW CHARACTER SET
Default Collations of the character set as follows
Big5 Traditional Chinese
DEC West European
DOS West European
HP West European
KOI8-R Relcom Russian
cp1252 West European
ISO 8859-2 Central European
ISO 8859-8 Hebrew
GB2312 Simplified Chinese
ISO 8859-7 Greek
Windows Central European
GBK Simplified Chinese
ISO 8859-9 Turkish
DOS Kamenicky Czech-Slovak
Mac Central European
Mac West European
DOS Central European
ISO 8859-13 Baltic
Binary pseudo charset
SJIS for Windows Japanese
UJIS for Windows Japanese
China National Standard GB18030
2. Create Table
Create table statement is used to create a table in the MySQL database.
Following the below Create table statement.
DROP TABLE IFEXISTS`testrecords`;
CREATE TABLE IFNOTEXISTS`testrecords`(
We can also create a table by using the PHPMYADMIN interface. The interface looks like.
The following way to create a table using PHP PDO.