Create a user in MySQL to grant permissions

Source: Internet
Author: User
1. Create a user:

Command: create user 'username' @ 'host' identified by 'Password ';

Description: username-the username you will create, host-specifies the host on which the user can log on. If a local user can use localhost, if you want to allow the user to log on from any remote host, you can use the wildcard %. password-the user's login password. The password can be blank. If it is blank, the user can log on to the server without the password.

Example: create user 'dog '@ 'localhost' identified by '123 ';
Create user 'pig' @ '192. 168.1.101 _ 'idendified by '123 ';
Create user 'pig' @ '%' identified by '000000 ';
Create user 'pig' @ '%' identified '';
Create user 'pig' @ '%'; create user 'countuser' @ '%' identified by 'count1234'; 2. Authorization:

Command: grant privileges on databasename. tablename to 'username' @ 'host'

Note: privileges-user operation permissions, such as select, insert, and update. use all .; databasename-Database Name, tablename-table name. If you want to grant the user the corresponding operation permissions on all databases and tables, it can be represented by *, as shown in *. *.

Example: grant select, insert on test. User to 'pig' @ '% ';
Grant all on *. * To 'pig' @ '% ';

Note: The user authorized with the preceding command cannot authorize other users. to authorize the user, run the following command:
Grant privileges on databasename. tablename to 'username' @ 'host' with grant option; example: grant select on *. * To 'countuser' @ 'count1234 ';

3. Set and change user passwords

Command: Set password for 'username' @ 'host' = PASSWORD ('newpassword'); if the current login user uses SET Password = PASSWORD ("newpassword ");

Example: Set password for 'pig' @ '%' = PASSWORD ("123456 ");

You can also:
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='name';   mysql> FLUSH PRIVILEGES;   mysql> QUIT 
Iv. Revoke User Permissions

Command: revoke privilege on databasename. tablename from 'username' @ 'host ';

Note: privilege, databasename, tablename-same as the authorization section.

Example: revoke select on *. * From 'pig' @ '% ';

Note: If you authorize the user 'pig' @ '%' like this (or similar): grant select on test. user to 'pig' @ '%', use revoke select on *. * From 'pig' @ '%'; the command does not cancel the Select Operation on the user table in the test database. conversely, grant select on * is used for authorization *. * To 'pig' @ '%'; then revoke select on test. user From 'pig' @ '%'; the command cannot revoke this user's SELECT statement from the user table in the test database.
Permission.

For more information, run the show grants for 'pig' @ '%' command.

5. delete a user

Command: Drop user 'username' @ 'host ';

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.