+------------+
1 row in set (0.00 sec)
mysql> use prod;
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| prod |
+------------+
1 row in set (0.00 sec)
mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| tom2@% |
+----------------+
1 row in set (0.00 sec)
mysql> show grants for tom2;
+------------------------------------------------------------------+
| Grants for tom2@% |
+------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'tom2'@'%' IDENTIFIED BY PASSWORD
|
| GRANT SELECT, INSERT, UPDATE ON `prod`.* TO 'tom2'@'%' |
+------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> show tables;
+----------------+
| Tables_in_prod |
+----------------+
| t1 |
| t2 |
+----------------+
2 rows in set (0.00 sec)
mysql> select * from t1;
+------+-------+
| id | name |
+------+-------+
| 10 | tom |
| 20 | jerry |
| 30 | rose |
+------+-------+
3 rows in set (0.00 sec)
mysql> select * from t2;
+------+-------+
| id | name |
+------+-------+
| 10 | tom |
| 20 | jerry |
| 30 | rose |
+------+-------+
3 rows in set (0.00 sec)
mysql> insert into t1 values (40,'john');
Query OK, 1 row affected (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.09 sec)
mysql> select * from t1;
+------+-------+
| id | name |
+------+-------+
| 10 | tom |
| 20 | jerry |
| 30 | rose |
| 40 | john |
+------+-------+
4 rows in set (0.00 sec)
mysql> update t1 set name='ellen' where id=40;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from t1;
+------+-------+
| id | name |
+------+-------+
| 10 | tom |
| 20 | jerry |
| 30 | rose |
| 40 | ellen |
+------+-------+
4 rows in set (0.00 sec)
mysql> delete from t1;
ERROR 1142 (42000): DELETE command denied to user 'tom2'@'192.168.8.254' for tab
le 't1'
mysql> commit;
Query OK, 0 rows affected (0.05 sec)
mysql> select * from t1;
+------+-------+
| id | name |
+------+-------+
| 10 | tom |
| 20 | jerry |
| 30 | rose |
| 40 | ellen |
+------+-------+
4 rows in set (0.00 sec)
4、回收tom2的update权限:
mysql> revoke update on prod.* from tom2;
Query OK, 0 rows affected (0.00 sec)
tom2再重新登陆:
C:\Users\Administrator>mysql -h 192.168.8.240 -utom2 -ptom2
mysql> use prod;
Database changed
mysql> update t1 set name='lily' where id=10;
ERROR 1142 (42000): UPDATE command denied to user 'tom2'@'192.168.8.254' for tab
le 't1'
---update失败!
二、修改用户口令:
1、root用户修改普通用户口令
mysql> set password for tom1=password('oracle');
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
tom1重新登陆:
C:\Users\Administrator>mysql -h 192.168.8.240 -utom1 -ptom1
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'tom1'@'192.168.8.254' (using passwor
d: YES)
---旧口令登陆失败!
C:\Users\Administrator>mysql -h 192.168.8.240 -utom1 -poracle
mysql>
2、普通用户修改自己密码:
C:\Users\Administrator>mysql -h 192.168.8.240 -utom1 -poracle
mysql> set password=password('tom1');
Query OK, 0 rows affected (0.00 sec)
重新登陆: C:\Users\Administrator>mysql -h 192.168.8.240 -utom1 -ptom1
mysql>
---新密码登陆成功 !
三、删除用户:
1、回收用户所有权限
mysql> revoke all on prod.* from tom2;
Query OK, 0 rows affected (0.01 sec)
2、删除用户
mysql> drop user tom2;
Query |