Home  >  Article  >  Database  >  How to create a database in mysql

How to create a database in mysql

下次还敢
下次还敢Original
2024-04-05 16:48:19738browse

The steps to create a database in MySQL are as follows: Connect to the MySQL server: mysql -u username -p Create a database: CREATE DATABASE database_name; Select the newly created database: USE database_name;

How to create a database in mysql

Creating a database in MySQL

Creating a database in MySQL is a simple process that only requires a few lines of commands.

Steps:

  1. Connect to MySQL Server

    To connect to MySQL Server, use The following command:

    <code>mysql -u username -p</code>

    where username is your MySQL username, -p means you need to enter your password.

  2. Create Database

    To create a database, use the following command:

    <code>CREATE DATABASE database_name;</code>

    Where, database_name is the name of the database you want to create.

  3. Select the newly created database

    To select the newly created database, use the following command:

    <code>USE database_name;</code>

Example:

The following is an example of creating a database named "my_database":

<code>mysql -u root -p
CREATE DATABASE my_database;
USE my_database;</code>

After successfully creating the database, you can create tables in it , insert data and perform other database operations.

The above is the detailed content of How to create a database in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn