Home >Database >Mysql Tutorial >How to create a new database mysql

How to create a new database mysql

下次还敢
下次还敢Original
2024-04-05 17:18:18778browse

How to create a new MySQL database? Connect to the MySQL server. Run command: CREATE DATABASE database_name; Grant access to other users (optional). Refresh permissions: FLUSH PRIVILEGES;

How to create a new database mysql

How to create a new MySQL database

Step 1: Connect to MySQL Server

Connect to the MySQL server using a terminal or command prompt. Enter the following command:

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

Among them,

  • -u root specifies the user name root
  • -p Tips Enter the password

Step 2: Create the database

After connecting to the server, run the following command to create the database:

<code>CREATE DATABASE database_name;</code>

Where, database_name is the name of the database to be created.

Step Three (Optional): Grant Permissions

If you need to grant other users access to the new database, run the following command:

<code>GRANT ALL ON database_name.* TO username;</code>

Among them,

  • username is the username to which permissions are to be granted
  • ALL Grant all permissions
  • * Grant permissions to all tables in the database

Step 4: Refresh permissions

Finally, refresh permissions to apply the changes:

<code>FLUSH PRIVILEGES;</code>

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