Home > Database > Mysql Tutorial > body text

How to create mysql database

下次还敢
Release: 2024-04-05 17:24:15
Original
944 people have browsed it

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>
Copy after login

Step 2: Create the database

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

Example:

<code>CREATE DATABASE my_database;</code>
Copy after login

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>
Copy after login

Example:

<code>USE my_database;</code>
Copy after login

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>
Copy after login
  • 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>
Copy after login

Step 5: Refresh permissions

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!