MySQL create user and authorization method

1. Create a user: 

Command: CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 

Description: username - the username you will create, host - specify which host the user can log in on, if it is a local user localhost, if you want the user to log in from any remote host, you can use the wildcard %. password - the user's login password, the password can be empty, if it is empty, the user can log in to the server without a password. 

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'@'%'; 

Second, authorization: 

Command: GRANT privileges ON databasename.tablename TO 'username'@'host' 

Description: privileges - user's operating authority, such as SELECT , INSERT , UPDATE , etc. (see the end of this article for a detailed list). If you want to grant all permissions, use ALL.;databasename - database name, tablename - table name, if you want to grant the user the corresponding operation permissions on all databases and tables, you can use *, such as *.*.

Example: GRANT SELECT, INSERT ON test.user TO 'pig'@'%'; 
GRANT ALL ON *.* TO 'pig'@'%'; 

Note: Users authorized by the above commands cannot authorize other users. To allow the user to authorize, use the following command: 
GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION; 

3. Set and change the user password 

command: SET PASSWORD FOR 'username'@'host' = PASSWORD( 'newpassword'); If it is the current login user, use SET PASSWORD = PASSWORD("newpassword"); 

Example: SET PASSWORD FOR 'pig'@'%' = PASSWORD("123456"); 

4. Revoke user privilege 

command: REVOKE privilege ON databasename.tablename FROM 'username'@'host'; 

Description: privilege, databasename, tablename - same as authorization part. 

Example: REVOKE SELECT ON *.* FROM 'pig'@'%'; 

Note: If you grant user 'pig'@'%' like this (or similar): GRANT SELECT ON test.user TO 'pig'@'%', then use REVOKE SELECT ON *.* The FROM 'pig'@'%'; command cannot revoke the user's SELECT operation on the user table in the test database. On the contrary, if the authorization is GRANT SELECT ON *.* TO 'pig'@'%'; REVOKE SELECT The ON test.user FROM 'pig'@'%'; command cannot revoke the user's Select permission to the user table in the test database. 

The specific information can be viewed with the command SHOW GRANTS FOR 'pig'@'%'; 

5. Delete User 

command: DROP USER 'username'@'host'; 

Schedule: Operation permissions in MySQL 

ALTER Allows use of ALTER TABLE.
ALTER ROUTINE Alters or drops stored routines.
CREATE Allows use of CREATE TABLE.
CREATE ROUTINE Creates stored routines.
CREATE TEMPORARY TABLE Allows use of CREATE TEMPORARY TABLE.
CREATE USER Allows use of CREATE USERDROP USERRENAME USER, and REVOKE ALL PRIVILEGES.
CREATE VIEW Allows use of CREATE VIEW.
DELETE Allows use of DELETE.
DROP Allows use of DROP TABLE.
EXECUTE Allows the user to run stored routines.
FILE Allows use of SELECT..INTO OUTFILE and LOAD DATA INFILE.
INDEX Allows use of CREATE INDEX and DROP INDEX.
INSERT Allows use of INSERT.
LOCK TABLES Allows use of LOCK TABLES on tables for which the user also has SELECT privileges.
PROCESS Allows use of SHOW FULL PROCESSLIST.
RELOAD Allows use of FLUSH.
REPLICATION Allows the user to ask where slave or master
CLIENT servers are.
REPLICATION SLAVE Needed for replication slaves.
SELECT Allows use of SELECT.
SHOW DATABASES Allows use of SHOW DATABASES.
SHOW VIEW Allows use of SHOW CREATE VIEW.
SHUTDOWN Allows use of mysqladmin shutdown.
SUPER Allows use of CHANGE MASTERKILLPURGE MASTER LOGS, and SET GLOBAL SQL statements. Allows mysqladmin debug command. Allows one extra connection to be made if maximum connections are reached.
UPDATE Allows use of UPDATE.
USAGE Allows connection without any specific privileges.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326035192&siteId=291194637