mysql> desc db;
+-----------------+-----------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-----------------+------+-----+---------+-------+
| Host | char(60) binary | | PRI | | |
| Db | char(64) binary | | PRI | | |
| User | char(16) binary | | PRI | | |
| Select_priv | enum('N','Y') | | | N | |
| Insert_priv | enum('N','Y') | | | N | |
| Update_priv | enum('N','Y') | | | N | |
| Delete_priv | enum('N','Y') | | | N | |
| Create_priv | enum('N','Y') | | | N | |
| Drop_priv | enum('N','Y') | | | N | |
| Grant_priv | enum('N','Y') | | | N | |
| References_priv | enum('N','Y') | | | N | |
| Index_priv | enum('N','Y') | | | N | |
| Alter_priv | enum('N','Y') | | | N | |
+-----------------+-----------------+------+-----+---------+-------+
13 rows in set (0.01 sec)
db表列出数据库,而用户有权限访问它们。在这里指定的权限适用于一个数据库中的所有表。
mysql> desc host;
+-----------------+-----------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-----------------+------+-----+---------+-------+
| Host | char(60) binary | | PRI | | |
| Db | char(64) binary | | PRI | | |
| Select_priv | enum('N','Y') | | | N | |
| Insert_priv | enum('N','Y') | | | N | |
| Update_priv | enum('N','Y') | | | N | |
| Delete_priv | enum('N','Y') | | | N | |
| Create_priv | enum('N','Y') | | | N | |
| Drop_priv | enum('N','Y') | | | N | |
| Grant_priv | enum('N','Y') | | | N | |
| References_priv | enum('N','Y') | | | N | |
| Index_priv | enum('N','Y') | | | N | |
| Alter_priv | enum('N','Y') | | | N | |
+-----------------+-----------------+------+-----+---------+-------+
12 rows in set (0.01 sec)
host表与db表结合使用在一个较好层次上控制特定主机对数据库的访问权限,这可能比单独使用db好些。这个表不受GRANT和REVOKE语句的影响,所以,你可能发觉你根本不是用它。
mysql> desc tables_priv;
+-------------+-----------------------------+----+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------------------------+----+
| Host | char(60) binary | | PRI | | |
| Db | char(64) binary | | PRI | | |
| User | char(16) binary | | PRI | | |
| Table_name | char(60) binary | | PRI | | |
| Grantor | char(77) | | MUL | | |
| Timestamp | timestamp(14) | YES | | NULL | |
| Table_priv | set('Select','Insert', | | | | |
| | 'Update','Delete','Create', | | | | |
| | 'Drop','Grant','References',| | | | |
| | 'Index','Alter') | | | | |
| Column_priv | set('Select','Insert', | | | | |
| | 'Update','References') | | | | |
+-------------+-----------------------------+----+
8 rows in set (0.01 sec)
tables_priv表指定表级权限。在这里指定的一个权限适用于一个表的所有列。
mysql> desc columns_priv;
+-------------+------------------------+------+---+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------------------+------+---+
| Host | char(60) binary | | PRI | | |
| Db | char(64) binary | | PRI | | |
| User | char(16) binary | | PRI | | |
| Table_name | char(64) binary | | PRI | | |
| Column_name | char(64) binary | | PRI | | |
| Timestamp | timestamp(14) | YES | | NULL | |
| Column_priv | set('Select','Insert', | | | | |
| | 'Update','References') | | | | |
+-------------+------------------------+------+---+
7 rows in set (0.00 sec)
columns_priv表指定列级权限。在这里指定的权限适用于一个表的特定列。
2)MySQL授权表运行机制:
MySQL的访问控制分两个步骤:
a)服务器检查是否允许该用户连接。