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

ID Topic: 31347 • Có 1,042 lượt xem
Hình đại diện của thành viên
#1 - @388313
07/05/2015 22:47
I - Login to MySQL

First we’ll login to the MySQL server from the command line with the following command:
Mã: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ã:mysql>

II - Create MySQL User

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

Mã: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ã: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ã: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ã:SELECT User,Host FROM mysql.user;

V - Drop MySQL User

We’ll drop user with the name testuser
Mã:DROP USER 'testuser'@'localhost';
(Cốc Cốc 47.0)
PM|Trích|Like|Sửa|Xóa|Báo cáo|Cảnh cáo
Sửa lần cuối: nghiatichxanh1992 11/07/2015 18:54
_______________
Diễn đàn chia sẻ kiến thức máy tính:
KETNOI123.COM

Ấn hiện ra để xem chữ ký của mình:
Trả lời nhanh

Chủ đề tương tự