Add, delete, modify and check mysql user rights management

mysql user rights management is often used and has been shared before, but there is absolutely no such detail.
This article will detail how to add, delete, modify and check mysql users.



1. Query the existing users and permissions of the mysql database

select `user`,`host` from mysql.user;

mysql> select `user`,`host` from mysql.user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| root          | %         |
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)

mysql>

2. Add a new user and authority to the mysql database

GRANT ALL PRIVILEGES ON *.* TO 'demo'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

FLUSH PRIVILEGES;

mysql> GRANT ALL PRIVILEGES ON *.* TO 'demo'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> select `user`,`host` from mysql.user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| root          | %         |
| demo          | localhost |
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
5 rows in set (0.00 sec)

mysql>

3. Modify a user and permissions in the mysql database

update mysql.user set `host`="%" where `user`="demo";

FLUSH PRIVILEGES;

mysql> update mysql.user set `host`="%" where `user`="demo";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> select `user`,`host` from mysql.user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| demo          | %         |
| root          | %         |
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
5 rows in set (0.00 sec)

mysql>

4. Delete a user and permissions in the mysql database

drop user 'demo'@'%';

FLUSH PRIVILEGES;

mysql> drop user 'demo'@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)

mysql> select `user`,`host` from mysql.user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| root          | %         |
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)

mysql>

Related articles written before


Friends, have you lost your studies?
See you next time! Bye-Bye!

Guess you like

Origin blog.csdn.net/frdevolcqzyxynjds/article/details/123281986