mysql--增删改查

#1 操作文件夹(库)
    增
        create database db1 charset utf8;

    查
        show databases;
        show create database db1;
    改
        alter database db1 charset gbk;
    删
        drop database db1;

#2 操作文件(表)
    切换到文件夹下:use db1

    增
        create table t1(id int,name char(10))engine=innodb;
        create table t2(id int,name char(10))engine=innodb default charset utf8;
    查
        show tables;
        show create table t1;

        desc t1;#查看表结构
    改
        alter table t1 add age int;
        alter table t1 modify name char(12);

    删
        drop table t1;

#3 操作文件的一行行内容(记录)
    增
        insert into db1.t1 values(1,'egon1'),(2,'egon2'),(3,'egon3');
        insert into db1.t1(name) values('egon1'),('egon2'),('egon3');
    查
        select * from t1;
        select name from t1;
        select name,id from t1;
    改
        update t1 set name='SB' where id=4;
        update t1 set name='SB' where name='alex';
    删
        delete from t1 where id=4;


        #对于清空表记录有两种方式,但是推荐后者
        delete from t1;
        truncate t1; #当数据量比较大的情况下,使用这种方式,删除速度快



    #自增id
    create table t5(id int primary key auto_increment,name char(10));
    create table t4(id int not null unique,name char(10));

insert into t5(name) values
#创建用户
create user 'lin'@'localhost' identified by '123';

#insert,delele,update,select
#级别1:对所有库,下的所有表,下的所有字段
grant select on *.* to 'lin1'@'localhost' identified by '123';

#级别2:对db1库,下的所有表,下的所有字段
grant select on db1.* to 'lin2'@'localhost' identified by '123';

#级别3:对表db1.t1,下的所有字段
grant select on db1.t1 to 'lin3'@'localhost' identified by '123';

#级别4:对表db1.t1,下的id,name字段
grant select (id,name) on db1.t1 to 'lin4'@'localhost' identified by '123';
grant select (id,name),update (name) on db1.t1 to 'lin5'@'localhost' identified by '123';

#修改完权限后,要记得刷新权限
flush privileges;

posted @ 2017-09-05 20:16  DaMoWang  阅读(173)  评论(0编辑  收藏  举报