Tạo Database và User MySQL bằng Lệnh (Command)

TricksMMO

Administrator
Staff member
** Cách tạo người dùng và cơ sở dữ liệu bằng MySQL thông qua dòng lệnh (đầu cuối) **

Thực hiện theo các bước bên dưới để tạo người dùng và cơ sở dữ liệu bằng MySQL thông qua dòng lệnh (thiết bị đầu cuối):

1. ** Đăng nhập MySQL **

Mở thiết bị đầu cuối và nhập lệnh sau:

`` `
mysql -u root -p
`` `

Nhập mật khẩu của bạn khi được nhắc.

2. ** Tạo cơ sở dữ liệu mới **

Để tạo cơ sở dữ liệu mới, hãy nhập lệnh sau:

`` `
Tạo cơ sở dữ liệu <Mame_of_Database>;
`` `

Thay thế `<name_of_database>` bằng tên của cơ sở dữ liệu bạn muốn tạo.

3. ** Tạo và cấp đặc quyền cho người dùng **

Để tạo người dùng và cấp đặc quyền cho người dùng, hãy nhập lệnh sau:

`` `
Tạo người dùng <Mame_of_user>@'LocalHost' được xác định bởi '<massge_of_user>';
cấp tất cả trên <name_of_database>.* to <name_of_user>@'localhost';
`` `

Thay thế những điều sau đây bằng các giá trị của riêng bạn:

* `<name_of_user>`: Tên của người dùng bạn muốn tạo.
* `<Massware_of_user>`: Mật khẩu của người dùng bạn muốn tạo.
* `<name_of_database>`: Tên của cơ sở dữ liệu bạn muốn cấp đặc quyền cho.

4. ** Đặc quyền tải lại **

Để tải lại các đặc quyền, hãy nhập lệnh sau:

`` `
đặc quyền xả nước;
`` `

5. ** Thoát khỏi MySQL **

Để thoát MySQL, hãy nhập lệnh sau:

`` `
lối ra;
`` `

**Ví dụ**

Dưới đây là một ví dụ về tất cả các lệnh bạn cần để tạo cơ sở dữ liệu, người dùng và đặc quyền cấp cho người dùng:

`` `
mysql -u root -p
tạo cơ sở dữ liệu dq_webite;
tạo người dùng Duyquang@localhost được xác định bởi '123456';
Cấp tất cả trên dq_webite.* Cho Duyquang@localhost được xác định bởi '123456';
đặc quyền xả nước;
lối ra;
`` `
=======================================
**How to create a user and database using MySQL through Command Line (Terminal)**

Follow the steps below to create a user and database using MySQL through Command Line (Terminal):

1. **Login MySQL**

Open Terminal and type the following command:

```
mysql -u root -p
```

Enter your password when prompted.

2. **Create new database**

To create a new database, type the following command:

```
create database <name_of_database>;
```

Replace `<name_of_database>` with the name of the database you want to create.

3. **Create and grant privileges to the user**

To create a user and grant privileges to the user, type the following command:

```
create user <name_of_user>@'localhost' identified by '<password_of_user>';
grant all on <name_of_database>.* to <name_of_user>@'localhost';
```

Replace the following with your own values:

* `<name_of_user>`: The name of the user you want to create.
* `<password_of_user>`: The password of the user you want to create.
* `<name_of_database>`: The name of the database you want to grant privileges to.

4. **Reload privileges**

To reload privileges, type the following command:

```
flush privileges;
```

5. **Exit MySQL**

To exit MySQL, type the following command:

```
exit;
```

**Example**

Here is an example of all the commands you need to create a database, user, and grant privileges to the user:

```
mysql -u root -p
create database dq_webite;
create user duyquang@localhost identified by '123456';
grant all on dq_webite.* to duyquang@localhost identified by '123456';
flush privileges;
exit;
```
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top