权限控制

测试了一下,也可以实现

mysql> create database test;
Query OK, 0 rows affected (0.22 sec)

mysql> create user ‘A’@‘192.168.%’ identified by ‘yx123456’;
Query OK, 0 rows affected (0.04 sec)

mysql> create user ‘B’@‘192.168.%’ identified by ‘yx123456’;
Query OK, 0 rows affected (0.04 sec)

mysql>
mysql> grant all privileges on test.* to ‘A’@‘192.168.%’;
Query OK, 0 rows affected (0.05 sec)

mysql> grant create on test.* to ‘B’@‘192.168.%’;
Query OK, 0 rows affected (0.06 sec)

mysql>
mysql> exit
Bye
[root@zabbix_server ~]#
[root@zabbix_server ~]# mysql -uA -pyx123456 -P4000 -h192.168.117.15
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 952107038
Server version: 8.0.11-TiDB-v7.5.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 8.0 compatible

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> show databases;
±-------------------+
| Database |
±-------------------+
| INFORMATION_SCHEMA |
| test |
±-------------------+
2 rows in set (0.00 sec)

mysql> use test;
Database changed
mysql> create table A_t1 (tid int);
Query OK, 0 rows affected (0.17 sec)

mysql> insert into A_t1 values (1);
Query OK, 1 row affected (0.02 sec)

mysql> exit
Bye
[root@zabbix_server ~]# mysql -uB -pyx123456 -P4000 -h192.168.117.15
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 952107040
Server version: 8.0.11-TiDB-v7.5.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 8.0 compatible

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
±---------------+
| Tables_in_test |
±---------------+
| A_t1 |
±---------------+
1 row in set (0.00 sec)

mysql> select * from A_t1;
ERROR 1142 (42000): SELECT command denied to user ‘B’@‘192.168.%’ for table ‘a_t1’
mysql> create table B_t1 (tid int);
Query OK, 0 rows affected (0.15 sec)

mysql> insert into B_t1 values (1);
ERROR 1142 (42000): INSERT command denied to user ‘B’@‘192.168.%’ for table ‘b_t1’
mysql> exit
Bye
[root@zabbix_server ~]# mylogin
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 952107042
Server version: 8.0.11-TiDB-v7.5.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 8.0 compatible

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> grant insert ,update ,delete ,select on test.B_t1 to B;
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql> grant insert ,update ,delete ,select on test.B_t1 to ‘B’@‘192.168.%’;
Query OK, 0 rows affected (0.04 sec)

mysql> exit
Bye
[root@zabbix_server ~]# mysql -uB -pyx123456 -P4000 -h192.168.117.15
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 952107044
Server version: 8.0.11-TiDB-v7.5.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 8.0 compatible

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> show databases;
±-------------------+
| Database |
±-------------------+
| INFORMATION_SCHEMA |
| test |
±-------------------+
2 rows in set (0.00 sec)

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
±---------------+
| Tables_in_test |
±---------------+
| A_t1 |
| B_t1 |
±---------------+
2 rows in set (0.01 sec)

mysql> select * FROM A_t1;
ERROR 1142 (42000): SELECT command denied to user ‘B’@‘192.168.%’ for table ‘a_t1’
mysql> select * from B_t1;
Empty set (0.00 sec)
mysql> insert into A_t1 values (1);
ERROR 1142 (42000): INSERT command denied to user ‘B’@‘172.17.%’ for table ‘a_t1’
mysql> delete from A_t1;
ERROR 1142 (42000): DELETE command denied to user ‘B’@‘172.17.%’ for table ‘a_t1’
mysql> update A_t1 set tid=2 ;
ERROR 1142 (42000): SELECT command denied to user ‘B’@‘172.17.%’ for table ‘a_t1’
mysql> insert into B_t1 values (1);
Query OK, 1 row affected (0.02 sec)

mysql> update B_T1 set tid=2 ;
Query OK, 1 row affected (0.12 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> delete from B_t1;
Query OK, 1 row affected (0.02 sec)

mysql> select * from B_t1;
Empty set (0.00 sec)

mysql> exit
Bye