MySQL creates users, authorizes users, revokes user permissions, changes user passwords, and deletes users (practical tips)

MySQL creates users, authorizes users, revokes user permissions, changes user passwords, and deletes users (practical tips)

MySQL creates users and authorizes and revokes user permissions

Operating environment: MySQL 5.0

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

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 ..

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;

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 authorization to user 'pig'@'%' like this (or something similar): GRANT SELECT ON test.user TO 'pig'@'%', then using the REVOKE SELECT ON . FROM 'pig'@'%'; command will not 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 also cannot revoke the user's Select privilege on the user table in the test database.

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

5. Deleting Users

Order:

DROP USER 'username'@'host';

The above is what I introduced to you about MySQL: creating users, authorizing users, revoking user permissions, changing user passwords, and deleting users (practical skills). 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
  • mysql5.7 create user authorization delete user revoke authorization
  • Specific method of viewing user authorization information in mysql
  • Detailed explanation of creating, deleting users, and authorizing and removing rights in mysql8

<<:  How to manage cached pages in Vue

>>:  Detailed tutorial on compiling and installing python3.6 on linux

Recommend

HTML table only displays the outer border of the table

I would like to ask a question. In Dreamweaver, I...

Solution to Nginx session loss problem

In the path of using nginx as a reverse proxy tom...

How to implement https with nginx and openssl

If the server data is not encrypted and authentic...

JavaScript BOM location object + navigator object + history object

Table of contents 1. Location Object 1. URL 2. Pr...

JavaScript canvas to load pictures

This article shares the specific code of JavaScri...

How does Vue solve the cross-domain problem of axios request front end

Table of contents Preface 1. Why do cross-domain ...

JavaScript Design Pattern Command Pattern

The command pattern is a behavioral design patter...

Docker completely deletes private library images

First, let’s take a look at the general practices...

Detailed explanation of MySQL replication principles and practical applications

This article uses examples to illustrate the prin...

Alibaba Cloud Ubuntu 16.04 builds IPSec service

Introduction to IPSec IPSec (Internet Protocol Se...

Example code for implementing dynamic skinning with vue+element

Sometimes the theme of a project cannot satisfy e...

MySQL 8.0.19 installation and configuration method graphic tutorial

This article records the installation and configu...

MySQL 5.7.17 installation and configuration graphic tutorial

Features of MySQL: MySQL is a relational database...