MYSQL以‘test’开头的库在授权时都会被当成test库处理
--------------------------------------------------------------------------------使用test登录-------------------------------------------------------
mysql> select user();
+----------------+
| user() |
+----------------+
| test@localhost |
+----------------+
1 row in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
| test_huzj_01 |
+--------------------+
3 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 grants;
+------------------------------------------------------------------------+
| Grants for test@localhost |
+------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'test'@'localhost' |
| GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'test'@'localhost' |
| GRANT SELECT ON `test`.`user` TO 'test'@'localhost' |
+------------------------------------------------------------------------+
3 rows in set (0.00 sec)
------------------------------------使用root赋权-----------------------------------------------------------------------
mysql> create database huzj_test01_01;
Query OK, 1 row affected (0.00 sec)
mysql> create database huzj_test01;
Query OK, 1 row affected (0.00 sec)
mysql> create database huzj_test02;
Query OK, 1 row affected (0.01 sec)
mysql> grant select on huzj_test01.* to 'test'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> grant select on huzj_test02.* to 'test'@'localhost';
Query OK, 0 rows affected (0.00 sec)
---------------------------------------------------使用test登录-------------------------------------------------------
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| huzj_test01 |
| huzj_test02 |
| test |
| test_huzj_01 |
+--------------------+
5 rows in set (0.00 sec)
--------------------------------------------------------------------------------使用test登录-------------------------------------------------------
mysql> select user();
+----------------+
| user() |
+----------------+
| test@localhost |
+----------------+
1 row in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
| test_huzj_01 |
+--------------------+
3 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 grants;
+------------------------------------------------------------------------+
| Grants for test@localhost |
+------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'test'@'localhost' |
| GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.* TO 'test'@'localhost' |
| GRANT SELECT ON `test`.`user` TO 'test'@'localhost' |
+------------------------------------------------------------------------+
3 rows in set (0.00 sec)
------------------------------------使用root赋权-----------------------------------------------------------------------
mysql> create database huzj_test01_01;
Query OK, 1 row affected (0.00 sec)
mysql> create database huzj_test01;
Query OK, 1 row affected (0.00 sec)
mysql> create database huzj_test02;
Query OK, 1 row affected (0.01 sec)
mysql> grant select on huzj_test01.* to 'test'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> grant select on huzj_test02.* to 'test'@'localhost';
Query OK, 0 rows affected (0.00 sec)
---------------------------------------------------使用test登录-------------------------------------------------------
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| huzj_test01 |
| huzj_test02 |
| test |
| test_huzj_01 |
+--------------------+
5 rows in set (0.00 sec)