mysql create users and assign permissions

First, create a user
command: CREATE USER 'username' @ ' host' IDENTIFIED BY 'password';
Description: username - user name you will create, host - Specifies that the user on which the host can log in, if it is a local user available localhost If you want the user can log in from any remote host, you can use wildcards% password - the user's login password, the password can be empty, if empty then the user can log in without a password mysql server.
examples:
the CREATE the uSER ' Dog '@' localhost 'the IDENTIFIED BY' 123456 ';
the CREATE the USER' pig'@'192.168.1.101_ 'IDENDIFIED BY' 123456 ';
the CREATE the USER' Pig '@'% 'the IDENTIFIED BY' 123456 ';
the CREATE the USER' Pig ' @ '%' the IDENTIFIED BY '';
the CREATE the USER 'Pig' @ '%';

Second, the authorization
command: GRANT privileges ON databasename.tablename TO 'username ' @ 'host'
Description:. Privileges - a user's operation authority, such as SELECT, INSERT, UPDATE, etc. (see list in detail the rearmost paper) is to be granted if the privileges using ALL; databasename - the database name, tablename- table, if you want to grant the user appropriate permissions to operations and all database tables is available representations, such as ...
examples:
the gRANT the SELECT, the INSERT the oN test.User the tO 'Pig '@'% ';
the GRANT the ON * the tO ALL.' Pig '@'% ';
Note: the user authorized by the above command is not authorized to other users, the user may want if authorized, with the following command:
the GRANT privileges the ON DatabaseName .tablename TO 'username' @ 'host ' WITH GRANT OPTION;

Three settings and change the user password
command: SET PASSWORD FOR 'username' @ 'host' = PASSWORD ( 'newpassword'); If you are currently logged in user with SET PASSWORD = PASSWORD ( "newpassword" );
example: SET PASSWORD FOR 'pig '@'% '= PASSWORD ( "123456");

Four revoke user rights
command: REVOKE privilege ON databasename.tablename FROM 'username ' @ 'host';
Description: privilege, databasename, tablename - with authorization moiety.
Examples: REVOKE SELECT ON FROM 'pig' @ '%';.
Note : If you are a user 'pig' @ '%' is such that when the authorization (or similar): GRANT SELECT oN test.user tO ' pig' @ '%', then use REVOKE SELECT oN FROM 'pig. '@'% '; does not revoke the command SELECT test user in the user table of the database operation contrary, if unauthorized use is GRANT SELECT oN tO..' pig '@'% '; the rEVOKE SELECT oN test.user FROM 'pig' @ '%'; command can not revoke the privileges of the user Select the test database user table (www.jb51.net script school).
specific information can use the command SHOW GRANTS fOR 'pig' @ ' %'; View .

Five delete user
command: DROP USER 'username' @ ' host';

Attached: grant command Detailed

Format :. Grant permissions 1, permission 2, ... permission n on the database name of the table name to 'username' @ 'user address' identified by 'connection password';

1) Permissions 1, permission 2, ... permission n represents select , insert, update, delete, create , drop, index, alter, grant, references, reload, shutdown, process, file permissions, etc. 14.
When the 1, 2 authority, ... n are all privileges or rights in place of all permissions given to the user indicates full access.

2) When the database name. * Is the table name. * Instead of representing all of the database tables give permission to all the user operation on the server.

3) The user address can be localhost, it can also be a ip address, machine name, domain name. Can also use the '%' indicates the connection from any address.

4). 'Connection password' can not be empty or the creation fails.

Note : After updating the database user permissions, update the data using the following command

    flush privileges

Examples :

Assign users remote access to the database

grant select,insert,update,delete on jarhumall.* to 'jarhumalldb'@'116.255.178.24' identified by 'xxxxx123'

Guess you like

Origin blog.csdn.net/weixin_41109346/article/details/81987391