Home  >  Article  >  Database  >  How to create mysql database

How to create mysql database

下次还敢
下次还敢Original
2024-04-05 17:24:15948browse

How to create a MySQL database

Step 1: Connect to the MySQL server

  • Open the MySQL command line client, such as MySQL Workbench or command prompt.
  • Connect to the MySQL server using the following command:
<code>mysql -u 用户名 -p 密码</code>

Step 2: Create the database

  • Use CREATE DATABASE Command to create a database, the syntax is as follows:
<code>CREATE DATABASE database_name;</code>
  • where database_name is the name of the database you want to create.

Example:

<code>CREATE DATABASE my_database;</code>

Step 3: Select new database (optional)

  • Create database, you need to switch to the new database to use it. Use the USE command with the following syntax:
<code>USE database_name;</code>

Example:

<code>USE my_database;</code>

Step 4: Grant permissions (optional)

  • If you need to grant other users access to the database, use the GRANT command with the following syntax:
<code>GRANT <权限> ON database_name TO <用户名>;</code>
  • For example, to grant user my_user all permissions to the my_database database, you can use the following command:
<code>GRANT ALL ON my_database TO my_user;</code>

Step 5: Refresh permissions

  • After granting permissions, you need to use the FLUSH PRIVILEGES command to refresh the permissions:
<code>FLUSH PRIVILEGES;</code>

The above is the detailed content of How to create mysql database. 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