mysql5.7 create user authorization delete user revoke authorization

mysql5.7 create user authorization delete user revoke authorization

1. Create a user:

Order:

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

Description: username - the username you will create, host - specifies the host on which the user can log in. If it is a local user, you can use localhost. If you want the user to log in from any remote host, you can use a wildcard. Password - the login password of the user. 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 'password';
    CREATE USER 'pig'@'192.168.1.100' IDENDIFIED BY 'password';
    CREATE USER 'pig'@'192.168.1.%' IDENDIFIED BY 'password';
    CREATE USER 'pig'@'%' IDENTIFIED BY 'password';
    CREATE USER 'pig'@'%' IDENTIFIED BY '';
    CREATE USER 'pig'@'%';

2. Authorization:

Order:

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

Note: privileges - user's operation privileges, such as SELECT, INSERT, UPDATE, etc. (see the end of this article for a detailed list). If you want to grant all privileges, use ALL.; databasename - database name, tablename - table name. If you want to grant the user corresponding operation privileges for all databases and tables, you can use * to represent it, 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 to allow the user to authorize, use the following command:

GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;

Privilege information is stored in the MySQL database (that is, in a database named mysql) using the user, db, host, tables_priv, and columns_priv tables.

Permission column Context

select Select_priv table

insert Insert_priv table

update Update_priv table

delete Delete_priv table

index Index_priv table

alter Alter_priv table

create Create_priv database, table, or index

drop Drop_priv database or table

grant Grant_priv database or table

references References_priv database or table

reload Reload_priv Server management

shutdown Shutdown_priv Server Management

process Process_priv Server Management

file File_priv File access on the server

3. Setting and changing user password

Order:

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

example:

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

4. Revoke user permissions

Order:

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

Note: privilege, databasename, tablename - Same as the authorization part.

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

Note: If you GRANT SELECT ON test.user TO 'pig'@'%', then REVOKE SELECT ON *.* FROM 'pig'@'%'; GRANT SELECT ON *.* TO 'pig'@'%'; ';, then REVOKE SELECT ON test.user REVOKE SELECT ON test.user FROM 'pig'@'% '; command cannot revoke the user's Select permission on the user table in the test database.

Detailed information can be viewed using the command SHOW GRANTS FOR 'pig'@'%'; ;.

5. Delete User

Order:

DROP USER 'username'@'host';

6. Check the user's authorization

mysql> show grants for 'test01'@'localhost';
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for test01@localhost |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'test01'@'localhost' |
| GRANT INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `test001`.* TO 'test01'@'localhost' |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.01 sec)
mysql> show grants for 'test02'@'localhost'; 
+-------------------------------------------------------------+
| Grants for test02@localhost |
+-------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'test02'@'localhost' |
| GRANT ALL PRIVILEGES ON `test001`.* TO 'test02'@'localhost' |
+-------------------------------------------------------------+
2 rows in set (0.00 sec)

The above is what I introduced to you about MySQL 5.7 creating user authorization, deleting user authorization, and revoking authorization. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • MySQL user creation and authorization method
  • MySql add user, authorization, change password and other statements
  • How to create, authorize, and revoke MySQL users
  • Sharing of methods for creating new users and authorization in MySQL
  • User authorization and authorization deletion methods in MySQL
  • mysql create database, add users, user authorization practical method
  • Specific method of viewing user authorization information in mysql
  • MySQL creates users, authorizes users, revokes user permissions, changes user passwords, and deletes users (practical tips)
  • Detailed explanation of creating, deleting users, and authorizing and removing rights in mysql8

<<:  Steps for Vue to use Ref to get components across levels

>>:  Centos7 startup process and Nginx startup configuration in Systemd

Recommend

Record the process of connecting to the local Linux virtual machine via SSH

Experimental environment: Physical machine Window...

A simple LED digital clock implementation method in CSS3

This should be something that many people have do...

CSS implementation code for drawing triangles (border method)

1. Implement a simple triangle Using the border i...

How to automatically deploy Linux system using PXE

Table of contents Background Configuring DHCP Edi...

Analysis of problems caused by MySQL case sensitivity

MYSQL is case sensitive Seeing the words is belie...

How to use pdf.js to preview pdf files in Vue

When we preview PDF on the page, some files canno...

Using JavaScript to implement carousel effects

This article shares the specific code for JavaScr...

Mysql string interception and obtaining data in the specified string

Preface: I encountered a requirement to extract s...

Detailed tutorial on running Tomcat in debug mode in IDEA Maven project

1. Add the following dependencies in pom.xml <...

HTML form application includes the use of check boxes and radio buttons

Including the use of check boxes and radio buttons...

Vue implements form data validation example code

Add rules to the el-form form: Define rules in da...

el-table in vue realizes automatic ceiling effect (supports fixed)

Table of contents Preface Implementation ideas Ef...

React error boundary component processing

This is the content of React 16. It is not the la...