How to Create Database in MySQL
MySQL is an open-source relational database management system (RDBMS) that is widely used by web developers and system administrators to store, manage, and retrieve data. It is very popular because of its scalability, flexibility, and performance. In this article, we will guide you through the process of creating a database in MySQL.
Step 1: Install MySQL
Before you can create a database in MySQL, you need to install it on your computer or server. You can download the latest version of MySQL from the official website, and follow the instructions to install it. Once you have installed MySQL, you will need to start the MySQL server.
Step 2: Access MySQL
To access MySQL, you need to use a client program such as MySQL Workbench, phpMyAdmin, or the MySQL command-line interface (CLI). In this tutorial, we will use the MySQL CLI.
To start the MySQL CLI, open a terminal window on your computer or server and enter the following command:
mysql -u root -p
This will prompt you to enter your MySQL root user password. Enter the password and press Enter.
Step 3: Create a Database
To create a database in MySQL, you need to use the CREATE DATABASE statement. The basic syntax of the statement is as follows:
CREATE DATABASE database_name;
database_name with the name of the database you want to create. For example, if you want to create a database called
mydb, you can use the following command:
CREATE DATABASE mydb;
Once you have executed this command, you should see a message that says “Query OK, 1 row affected”.
Step 4: Verify the Database
To verify that the database has been created, you can use the SHOW DATABASES statement. This statement displays a list of all the databases that have been created in MySQL.
This should display a list of all the databases, including the one you just created.
Step 5: Use the Database
To start using the database you just created, you need to select it using the USE statement. The syntax of the statement is as follows:
For example, to start using the
mydb database, you can use the following command:
Once you have executed this command, you should see a message that says “Database changed”.