MySQL Create user and authorization

Source: Internet
Author: User
Tags mysql create mysql create user

One. Create user command:
CREATE USER ' username '@'host'by'password';
Description
    • Username: The user name you will create
    • Host: Specifies on which host the user can log on, if localhost is available to the local user, if you want the user to be able to log in from any remote host , you can use a wildcard character%
    • Password: The user's login password, password can be empty, if it is empty, the user can not need password login server
Example:
CREATE USER 'Dog'@'localhost'Identified by '123456';CREATE USER 'Pig'@'192.168.1.101_'Idendified by '123456';CREATE USER 'Pig'@'%'Identified by '123456';CREATE USER 'Pig'@'%'Identified by "';CREATE USER 'Pig'@'%';
Two. Authorization: command:
GRANT Privileges  on  to ' username '@'host'
Description
    • Privileges: User's operation permissions, such as,, SELECT INSERT UPDATE etc., if the permission to be granted is usedALL
    • DatabaseName: Database name
    • TableName: Table name, if you want to grant the user the appropriate operation permissions on all databases and tables * , the representation is available, such as*.*
Example:

  

GRANT SELECT,INSERT  onTest.User  to 'Pig'@'%';GRANT  All  on *.*  to 'Pig'@'%';GRANT  All  onMaindataplus.*  to 'Pig'@'%';
Attention:

A user authorized with the above command cannot authorize another user, and if you want the user to be authorized to do so, use the following command:

GRANT Privileges  on  to ' username '@'host'withGRANTOPTION;
Three. Set and change user password commands:
SET  for ' username '@'host'= PASSWORD ('newpassword');

If the current user is logged in with:

SET = PASSWORD ("NewPassword");
Example:
SET  for ' Pig '@'%'= PASSWORD ("123456");
Four. Revoke User Rights command:
REVOKE  on  from ' username '@'host';
Description

Privilege, DatabaseName, TableName: With the authorization section

Example:
REVOKE SELECT  on *. *  from ' Pig '@'%';
Attention:

If you ‘pig‘@‘%‘ are doing this (or the like) when authorizing a user, the use of a GRANT SELECT ON test.user TO ‘pig‘@‘%‘ command does REVOKE SELECT ON *.* FROM ‘pig‘@‘%‘; not revoke the user's action on the users table in the test database SELECT . Conversely, if authorization is used, GRANT SELECT ON *.* TO ‘pig‘@‘%‘; the REVOKE SELECT ON test.user FROM ‘pig‘@‘%‘; command cannot revoke the user's permissions to the users table in the test database Select .

Specific information can be viewed with commands SHOW GRANTS FOR ‘pig‘@‘%‘; .

Five. Delete User command:
DROP USER ' username '@'host';

MySQL Create user and authorization

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.