How to create mysql database

下次还敢
Release: 2024-04-05 17:24:15
Original
880 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:
mysql -u 用户名 -p 密码
Copy after login

Step 2: Create the database

  • UseCREATE DATABASECommand to create a database, the syntax is as follows:
CREATE DATABASE database_name;
Copy after login
  • wheredatabase_nameis the name of the database you want to create.

Example:

CREATE DATABASE my_database;
Copy after login

Step 3: Select new database (optional)

  • Create database, you need to switch to the new database to use it. Use theUSEcommand with the following syntax:
USE database_name;
Copy after login

Example:

USE my_database;
Copy after login

Step 4: Grant permissions (optional)

  • If you need to grant other users access to the database, use theGRANTcommand with the following syntax:
GRANT <权限> ON database_name TO <用户名>;
Copy after login
  • For example, to grant usermy_userall permissions to themy_databasedatabase, you can use the following command:
GRANT ALL ON my_database TO my_user;
Copy after login

Step 5: Refresh permissions

  • After granting permissions, you need to use theFLUSH PRIVILEGEScommand to refresh the permissions:
FLUSH PRIVILEGES;
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
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!