About MySQL create user and authorization method

The implementation method of creating users and authorization in MySQL, for friends who are new to mysql, you can refer to the following

Note: My operating environment is widnows xp professional + MySQL5.0

. Create a user:

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

Description: username - the username you will create, host - specify On which host the user can log in, if it is a local user, localhost can be used, if you want the user to log in from any remote host, you can use the wildcard %. password - the login password of the user, the password can be empty, if it is empty then 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 operation authority, such as SELECT, INSERT, UPDATE, etc. (see the end of this article for a detailed list). If you want to grant the authority, use ALL.; databasename - database name, tablename - table name, if you want to grant The user’s corresponding operation authority on all databases and tables can be represented by *, such as *.*.

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

Note: The user authorized by the above command cannot authorize other users. If you want the user to be authorized, use the following command:
GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION

; .Set and change 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 authorize user 'pig'@'%' like this (or similar): GRANT SELECT ON test.user TO 'pig'@'%', then using REVOKE SELECT ON *.* 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'@'%'; then the REVOKE SELECT 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

used Command SHOW GRANTS FOR 'pig'@'%'; View.

Five. Delete user

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

Attached table: Operation authority 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 USER, DROP USER, RENAME 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 MASTER, KILL, PURGE 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.

转自:微点阅读   https://www.weidianyuedu.com

Guess you like

Origin blog.csdn.net/weixin_45707610/article/details/131808242