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

Linux sftp command usage

Concept of SFTP sftp is the abbreviation of Secur...

Detailed explanation of Linux host name modification command

Linux change hostname command 1. If you only need...

Detailed discussion of InnoDB locks (record, gap, Next-Key lock)

Record lock locks a single index record. Record l...

JS implements a simple counter

Use HTML CSS and JavaScript to implement a simple...

MySQL replication table details and example code

MySQL replication table detailed explanation If w...

Differences and usage examples of for, for...in, for...of and forEach in JS

for loop Basic syntax format: for(initialize vari...

Two query methods when the MySQL query field type is json

The table structure is as follows: id varchar(32)...

Learn the operating mechanism of jsBridge in one article

Table of contents js calling method Android 1.js ...

Vue calls the computer camera to realize the photo function

This article example shares the specific code of ...

Native js realizes the drag and drop of the nine-square grid

Use native JS to write a nine-square grid to achi...

Solve the problem of Mac Docker x509 certificate

question Recently I needed to log in to a private...

In-depth explanation of Vue multi-select list component

A Multi-Select is a UI element that lists all opt...