1. 新建数据库testdb
create datebase testdb;
2. 新建用户 laowang 并赋予 testdb数据库相应的权限
grant all privileges on testdb.* to laowang@localhost identified by '123';
3. 如果想指定部分的权限给用户
grant select, update on testdb.* to laowang@localhost identified by '123';
4. 赋予用户 laowang 所有数据库的某些权限
grant select, update, insert, create, drop on *.* to laowang@"%" identified by '123';
注意:all privileges, *.*, "%"(所有的登陆主机)
常用的权限
select 对所有表进行查询操作
insert 对所有表进行插入操作
update 对所有表进行更新操作
delete 对所有表进行删除操作
create 数据库、表、索引
drop 数据库和表的删除操作
alter 对所有表进行更改
create table index_tb1(
id int primary key auto_increment,
name varchar(32)
);
create index index_name on index_tb1(name);
格式:alter table table_name add index index_name(column);
- 查看索引
- 语法格式:show index from table_name;
- 删除索引
- 语法格式:drop index index_name on table_name;
- drop index index_name on index_tb1;
注意:使用整型优于字符型,额外维护一个与其他字段不相关的列,一般设置为整数类型并且自增长。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。