[root@localhost ~]# mysql -u root -p //重新登录
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
mysql> select * from ltp123; ##重新登入后之前创建的临时表消失
ERROR 1046 (3D000): No database selected
创建自定义临时表
mysql> create temporary table ltptem(students char(16) not null,class char(16) not null,primary key (students)); ##创建自定义的临时表
mysql> insert into ltptem values(‘li’,‘2’);
Query OK, 1 row affected (0.00 sec)
mysql> select * from ltptem;
±---------±------+
| students | class |
±---------±------+
| li | 2 |
±---------±------+
1 row in set (0.00 sec)
用户授权管理
用户授权
语法格式
grant 权限列表 on 数据库名.表名 to 用户名@来源地址 [identified by '密码']
1
1
示例
mysql> grant select on bbs.* to ‘ltp_admin’@‘localhost’ identified by ‘123456’;
Query OK, 0 rows affected, 1 warning (0.00 sec) ##授予本地登入的ltp_admin管理账号查询bbs数据库的权限,身份验证码为“123456”
mysql> \q 退出
Bye
[root@localhost ~]# mysql -u ltp_admin -p ##用ltp_admin管理账号登入
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
mysql> show grants; ##查看授权,可以看到有select查看权限
±---------------------------------------------------+
| Grants for ltp_admin@localhost |
±---------------------------------------------------+
| GRANT USAGE ON
.
TO ‘ltp_admin’@‘localhost’ |
| GRANT SELECT ON “bbs”.* TO ‘ltp_admin’@‘localhost’ |
±---------------------------------------------------+
2 rows in set (0.00 sec)
删除授权
语法格式
revoke 权限列表 on 数据库名.表名 from 用户名@来源地址
1
1
示例
mysql> revoke all on bbs.* from ‘ltp_admin’@‘localhost’; ##删除本地访问的ltp_admin用户所有关于bbs数据库的授权
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for ‘ltp_admin’@‘localhost’; ## 查看ltp_admin的授权情况,发现已无授权
±----------------------------------------------+
| Grants for ltp_admin@localhost |
±----------------------------------------------+
| GRANT USAGE ON
.
TO ‘ltp_admin’@‘localhost’ |
±----------------------------------------------+
1 row in set (0.01 sec)
mysql> \q
Bye
[root@localhost ~]# mysql -u ltp_admin -p ## 进入ltp_admin账户测试
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
mysql> use bbs ## 发现使用bbs数据库的权限也没有了
ERROR 1044 (42000): Access denied for user ‘ltp_admin’@‘localhost’ to database ‘bbs’