In this post, we will discuss how to create a database in MySQL using the command line and phpMyAdmin.

According to MySQL documentation, the general syntax to create a database using the command line is

The syntax inside square brackets are optional, where

  • The IF NOT EXISTS syntax ensures that the particular database if exists then we do not get an error.
  • CHARACTER SET option specifies the default database character set and
  • COLLATE option specifies the default database collation.

Most of the times we do not require these options and so we can simplify the command to create MySQL database into

Let’s see how we can use this command to create a database in MySQL using command line or phpMyAdmin.

Create Database in MySQL using Command Line

Note: Make sure that MySQL is installed on your machine or server otherwise download it from here.

  1. Open command line and log in to the MySQL Server using the root user using mysql -u root -p. For MySQL command line root is by default selected. open MySQL
  2. Input the password or simply press ENTER, if the password is not set to the root user.
  3. Type the following command CREATE DATABASE database_name;, replacing the database_name with the name of database of your choice.
  4. Type SHOW databases; to see the list of databases along with the new database which you have created just now.
  5. The new database is created but is not in use, so type USE database_name; replacing the database_name with the new database name which you have created in the prvious steps.

create a database in MySQL

The new database in MySQL is created and is ready for use.

Create Database in MySQL using phpMyAdmin

There are two ways to create a database using phpMyAdmin.

  1. Using SQL command create database database_name;
  2. Without using any command.

Create database using SQL Command

To create database using SQL command, simply Go to SQL tab > Enter the SQL command create database database_name; > Run.

create MySQL database using SQL command in phpMyAdmin

Note: Make sure to replace database_name with the name of your database.

Create database without using SQL Command

To create MySQL database without using any SQL command, simply Go to DATABASES tab > Enter the database name > Create.

create MySQL database without SQL command in phpMyAdmin

That’s all you need to do in order to create a database in MySQL. If you have any doubts or suggestion then please comment below.

This Post Has 2 Comments

Leave a Reply