How does the mysql database add users and authorize them?
Query all users
Method 1:
Mysql > select host, user, password from mysql.user;-before version 5.7mysql > select host, user, authentication_string from mysql.user;-after version 5.7, including
Mode 2:
Mysql > select distinct concat ('User:'', user,'''@''',host,''';') as query from mysql.user
Query user permissions
All indicates all permissions
Select means to check permissions only.
Update means to change permissions only.
Delete means to delete only permissions and so on.
Method 1:
Mysql > show grants for "user" @ "host"; mysql > show grants for "root" @ "localhost"
Mode 2:
Mysql > select * from mysql.user where user='root'\ G
Add authorized users (newly created users, who do not have any permissions by default): log in to the database using the root user
The format of the command is as follows:
Mysql > create user "username" @ "IP address" identified by "password"; mysql > create user "haidon" identified by "123456";-in this case, the password is 123456 and the host value is%. Mysql > create user "haidon" @ "%" identified by "123456";-- password 123456 in this case
Assign user permissions (authorize users)
The format of the command is as follows:
Mysql > grant permission type on database name. Table name to 'username' @'ip address' identified by 'user password' with grant option
The following types of permissions are commonly used:
All privileges: all permissions.
Select: read permission.
Create: create permissions.
Delete: delete permissions.
Update: update permissions.
Drop: delete database and data table permissions.
Allow access to all tables under all databases
Mysql > grant all privileges on *. * to 'username' @ 'specify ip' identified by' user password'
Allow access to all tables under the specified database
Mysql > grant all privileges on test.* to 'username' @ 'specify ip' identified by' user password'
Allow access to the specified table under the specified database
Mysql > grant all privileges on test.test to 'username' @ 'specify ip' identified by' user password'; mysql > grant all privileges on tornado.* to 'haidon'@'%' identified by' 123456'
Revoke user rights (using root user actions)
Mysql > revoke select on tornado.* from "haidon" @ "%"; mysql > revoke all on tornado.* from "haidon" @ "%"
Delete authorized user
Mysql > drop user "haidon" @ "%";-- delete method 1mysql > delete from mysql.user where user= "haidon";-- delete method 2
Refresh permissions
Mysql > flush privileges
These are the details of adding users and authorizing users in the mysql implementation. For more information, please follow other related articles!