fected (0.00 sec)
mysql> show grants for tom;
+----------------------------------------------------------------------------------------------------+
| Grants for tom@% |
+----------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'tom'@'%' IDENTIFIED BY PASSWORD '*71FF744436C7EA1B954F6276121DB5D2BF68FC07' |
| GRANT ALL PRIVILEGES ON `prod`.* TO 'tom'@'%' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> use mysql;
Database changed
mysql> select user,host from user ;
+-------+-----------+
| user | host |
+-------+-----------+
| tom | % |
| tom1 | % |
| tom2 | % |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| scott | localhost |
| tom | localhost |
| | mysrv |
| root | mysrv |
+-------+-----------+
11 rows in set (0.00 sec)
tom登陆:
[root@mysrv ~]# mysql -u tom -ptom prod
mysql> select database();
+------------+
| database() |
+------------+
| prod |
+------------+
1 row in set (0.01 sec)
mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| tom@localhost |
+----------------+
1 row in set (0.00 sec)
创建表:
mysql> show tables;
+----------------+
| Tables_in_prod |
+----------------+
| t1 |
+----------------+
1 row in set (0.00 sec)
mysql> create table t2 as select * from t1;
Query OK, 3 rows affected (0.15 sec)
Records: 3 Duplicates: 0 Warnings: 0
查看表信息:
mysql> desc t2;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(10) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.01 sec)
mysql> show create table t2;
+-------+---------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+---------------------------------------------------------------------------------------------------------------------------+
| t2 | CREATE TABLE `t2` (
`id` int(11) DEFAULT NULL,
`name` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+---------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
mysql> show create table t2\G;
*************************** 1. row ***************************
Table: t2
Create Table: CREATE TABLE `t2` (
`id` int(11) DEFAULT NULL,
`name` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
mysql> select * from t2;
+------+-------+
| id | name |
+------+-------+
| 10 | tom |
| 20 | jerry |
| 30 | rose |
+------+-------+
3 rows in set (0.00 sec)
3、tom用户为tom1,tom2授权
mysql> grant select on prod.* to tom1;
Query OK, 0 rows affected (0.00 sec)
mysql> grant select on prod.* to tom2;
Query OK, 0 rows affected (0.02 sec)
mysql> grant insert,update on prod.* to tom2;
Query OK, 0 rows affected (0.00 sec)
tom2登陆(从远程登陆):
C:\Users\Administrator>mysql -h 192.168.8.240 -utom2 -ptom2
mysql> select database();
+------------+
| database() |
+------------+
| NULL | |