Home  >  Article  >  Database  >  MySQL practical tips for creating users, authorizing users, revoking user permissions, changing user passwords, and deleting users

MySQL practical tips for creating users, authorizing users, revoking user permissions, changing user passwords, and deleting users

黄舟
黄舟Original
2017-03-18 14:15:461411browse

This article mainly introduces MySQL Creating users, authorizing users, revoking user permissions, changing user passwords, Deleting users (practical tips), friends in need can refer to the following

MySQL creates users and authorizes and revokes user permissions

Running environment: MySQL5.0

1. Create User

Command:

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

Instructions: username - the user name you will create, host - specify the host on which the user can log in, if it is a local user, it is available localhost, if you want the user to log in from any remote host, you can use the wildcard character %. password - the user's login password. The password can be empty. If it is empty, the user can log in to mysql without a password. Server.

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

Command:

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

Description: privileges - User's operation permissions, such as SELECT, INSERT, UPDATE, etc. (see the end of this article for a detailed list). If you want to grant all permissions, use ALL.;databasename - database Name, tablename - table name, if you want to grant the user corresponding operation permissions on all databases and tables, you can use the expression, such as...

Example:

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

Note: Use the above command to authorize The user cannot authorize other users. If you want the user to be able to authorize, use the following command:

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

3. Set and change user password

Command:

SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');

If you are the currently logged in user, use SET PASSWORD = PASSWORD("newpassword");

Example:

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

4. Revoke user permissions

Command:

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

Instructions: privilege, databasename, tablename - the same as the 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 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 to use GRANT SELECT ON . TO 'pig'@'%'; then the
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 with the command SHOW GRANTS FOR 'pig'@'%';.

5. Delete users

Command:

DROP USER 'username'@'host';

The above is the detailed content of MySQL practical tips for creating users, authorizing users, revoking user permissions, changing user passwords, and deleting users. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn