mysql user and permission management allows remote connections

Mysq, a powerful relational database, its user management is of course particularly important in the development process. Next, let's take a look at the user management of mysql

1. Log in to the database

mysql -uroot -p Enter

Enter password... Enter

 

2. After the login is successful, switch the database

mysql>use mysql;

 

3. View current users

mysql>select user,host from user;

There are only two fields listed here. There are many fields in this table. Generally, these are the ones I pay more attention to:

host: access host

user: access user name

plugin: Authentication method (password encryption method)

authentication_string: a long string of characters after the password is encrypted

 

4. Add new users

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

host: host ip, % [arbitrary ip] localhost [local] 192.168.31.22 [specified ip]

IDENTIFIED BY: Encrypt the password with the default encryption method and put it in the table.

 

The default encryption method needs to check the plugin in the user table. If the client does not support it, you can specify the encryption method for encryption.

mysql>CREATE USER 'username'@'host' IDENTIFIED MySqlSHA1 BY 'password'; 

The newly added user does not have any permissions by default, that is, useage, and can only log in.

 

5. View the permissions of users in the MYSQL database
mysql>show grants for  'username'@'host' ;
 
6. User authorization
mysql>grant privileges on dbname.tabname to "username"@"host"
privileges : permissions, select [query], update [update], delete [delete], etc., all [all]
Such an authorized user has all permissions, but cannot manage other users. If you want this user to authorize other users, add with grant option.
grant privileges on dbname.tabname to "username"@"host" with grant option
 
 
7. Modify user
mysql>update user set host="localhost" where user="username"
User, host and plugin can all use the update statement. After modifying the plugin, you need to modify the password again, otherwise it will be invalid. You can also specify the encryption method when modifying the password, and you do not need to modify the plugin.
Modifying the encryption method of the user password is generally only when the client does not support the encryption method on the server side. If it supports, the encryption method can generally not be modified. MySQL 8.0 needs to modify the encryption method, otherwise the graphical tool has no way at all. connect.
 
8. Delete users, delete according to the user name, or according to the host
mysql>delete user where user="username"

 

Note: Allowing remote is to change the user's access address from localhost to % or specify ip. After allowing remote, you must set permissions, otherwise the user can only log in, and nothing else can be done. Of course, you want to play with him, You can, as long as you are happy.

 

9. User operation, the last step, update permissions

mysql>flush privileges

 

Okay! Only share so much, wait for me to drink some ink and come back to continue.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325016704&siteId=291194637