(9) MySQL user and authority management

(1) User management

1) log in and out of mysql

Example:
mysql -h192.168.111.150 -P3306 -uroot -predhat mysql -e 'select user,host,authentication_string from mysql.user'
-h specify hostname [default is localhost]
-P MySQL port [default is 3306]
- u specify the user name [default is root]
-p specify the login password [default is empty]
where mysql is the database for the specified login
-e connect the SQL statement

2) Create a user

Method 1: create user statement to create
create user user1@'localhost ' identified by 'password';
method 2: grant statement to create
grant all on . to 'user1'@'localhost ' identified by 'password';
grant all on blog.* to 'user2'@'% ' identified by 'password';

3) delete user

  • 方法一:drop user
    drop user 'user1'@'localhost';
  • Method 2: delete statement delete
    delete from mysql.user where user='user1' and host='localhost';
    flush privileges;

    4) Modify user password

Guess you like

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