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

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: Admin, Mod, SMod

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

Gửi bàigửi bởi nghiammo1992 » 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ã: 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: nghiammo1992 11/07/2015 18:54
Hình đại diện của thành viên
nghiammo1992
☀️2/30☀️
☀️2/30☀️
 
Bài viết: 15
Ngày tham gia: 08/03/2012 10:56
Đến từ: Hà Giang
Thiết bị: Nokia N96
Số điện thoại: 0367790762

Quay về VPS - Server

 


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

Ai đang trực tuyến?

Đang xem chuyên mục này: Không có thành viên nào đang trực tuyến20 khách