Bang hộiTiền mặt: 0 Xu Trò chơiHộp quà giáng sinhChủ Nhật, 15:45:25 - 28/04/2024
Chia sẻ kiến thức sử dụng VPS (máy chủ ảo) - Server (máy chủ riêng)

Các điều hành viên: Mod, SMod, Admin

How to create a MySQL User on VPS Linux - Hướng tạo tạo user MySQL trong VPS Linux

How to create a MySQL User on VPS Linux - Hướng tạo tạo user MySQL trong VPS Linux

#1 » Gửi bài gửi bởi nghiatichxanh1992 » 07/05/2015 22:47 » @388313

I - Login to MySQL

First we’ll login to the MySQL server from the command line with the following command:
Mã: Chọn tất cả
mysql -u root -p


In this case, I’ve specified the user root with the -u flag, and then used the -p flag so MySQL prompts for a password. Enter your current password to complete the login.

You should now be at a MySQL prompt that looks very similar to this:
Mã: Chọn tất cả
mysql>


II - Create MySQL User

We’ll create a user with the name testuser , and the password test123test

Mã: Chọn tất cả
CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'test123test';


That’s it, congratulations! In just one command you’ve created your first MySQL user. However, this user won’t be able to do anything with MySQL until they are granted additional privileges. In fact, they won’t even be able to login without additional permissions.

III - Grant Permissions to MySQL User

The basic syntax for granting permissions is as follows:
Mã: Chọn tất cả
GRANT permission ON database.table TO 'user'@'localhost';


Here is a short list of commonly used permissions :
  1. ALL – Allow complete access to a specific database. If a database is not specified, then allow complete access to the entirety of MySQL.
  2. CREATE – Allow a user to create databases and tables.
  3. DELETE – Allow a user to delete rows from a table.
  4. DROP – Allow a user to drop databases and tables.
  5. EXECUTE – Allow a user to execute stored routines.
  6. GRANT OPTION – Allow a user to grant or remove another user’s privileges.
  7. INSERT – Allow a user to insert rows from a table.
  8. SELECT – Allow a user to select data from a database.
  9. SHOW DATABASES- Allow a user to view a list of all databases.
  10. UPDATE – Allow a user to update rows in a table.

Example: To grant ALL permissions for all databases and all tables to the testuser, use the following command:
Mã: Chọn tất cả
GRANT ALL ON *.* TO 'testuser'@'localhost';


Using an asterisk (*) in the place of the database or table is a completely valid option, and implies all databases or all tables.

IV - View a List of MySQL Users

Viewing a full list of MySQL users, including the host they’re associated with, can be done with the following select statement:
Mã: Chọn tất cả
SELECT User,Host FROM mysql.user;


V - Drop MySQL User

We’ll drop user with the name testuser
Mã: Chọn tất cả
DROP USER 'testuser'@'localhost';
Sửa lần cuối: nghiatichxanh1992 11/07/2015 18:54
nghiatichxanh1992 ✅
Hình đại diện của thành viên
Rank: ☀️2/30☀️
Cấp độ:
Tu luyện:
Like:
Online:
Bang hội: Tiếu Ngạo
Xếp hạng Bang hội: ⚡5/60⚡
Level:
Chủ đề đã tạo: 🩸4140/4140🩸
Tiền mặt:
Ngân hàng:
Nhóm:
Danh hiệu: ⚝Truyền Thuyết⚝
Giới tính:
Ngày tham gia:
Đến từ:
Thiết bị:
Số điện thoại:
(Cốc Cốc 47.0)


Quay về VPS - Server

 


  • Chủ đề tương tự
    Trả lời
    Xem
    Bài viết mới nhất