Home > Database > Mysql Tutorial > body text

How to create a new database mysql

下次还敢
Release: 2024-04-05 17:18:18
Original
770 people have browsed it

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

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

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

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

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!

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 Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template