mysql基本操作(五)-视图,用户管理和索引
分类:
文章
•
2023-11-01 19:52:28
student表
1 创建视图:create view 视图名 as (select 字段名列表 from 表名);
2 插入数据:insert into 视图名 values(插入数据);
3 修改数据:update 视图名 set 待更改是数据 where 条件;
4 删除数据:delete from stu where 条件;
5 修改视图:alter view 视图名 as (select 字段名列表 from 表名);
6 查看视图:show create view 视图名;
7 删除视图:drop view 视图名;
索引操作
8 创建表时创建索引:create table 表名 (字段名 字段类型 ,索引类型(字段名))(index()普通索引,unique index 索引名(字段名)唯一性索引, fulltext index 索引名(字段名)全文索引,index 索引名(字段名列表) 多列索引,spatial index 索引名(字段名) 空间索引);
9 在已存在的表上建立索引:create 索引类型 索引名 on 表名(加索引的字段名);(index()普通索引,unique index 索引名(字段名)唯一性索引, fulltext index 索引名(字段名)全文索引,index 索引名(字段名列表) 多列索引,spatial index 索引名(字段名) 空间索引)
10 修改索引:alter table 表名 add 索引类型 索引名(字段名);
11 删除索引:drop 索引类型 索引名 on 表名;
用户管理
12 创建用户:
12.1 create user ‘用户名’@’localhost’ identified by ‘密码’;
12.2 grant 权限列表 on . to ‘用户名’@’localhost’ identified by ‘密码’;
12.3 insert into(Host,User ,Password,ssl_cipher,x509_subject) values(主机名,用户名,密码,”,”) ;
13删除用户:
13.1 drop user ‘用户名’@’localhost’;
13.2 delete from mysql.user where Host=’localhost’ and user=’用户名’;
14 修改密码:mysqladmin -u username -p password ‘new_password’(bin目录下);
15 取消权限:revoke 权限 on . from ‘用户名’@’localhost’;
16 查看权限:
16.1 select * from user;
16.2 show grants for ‘用户名’@’localhost’;