Home > Database > Mysql Tutorial > body text

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

黄舟
Release: 2017-03-18 14:15:46
Original
1367 people have browsed it

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';
Copy after login

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'@'%';
Copy after login

2. Authorization

Command:

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

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'@'%';
Copy after login

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;
Copy after login

3. Set and change user password

Command:

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

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

Example:

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

4. Revoke user permissions

Command:

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

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';
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!