zoukankan      html  css  js  c++  java
  • 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;

  • 相关阅读:
    Perl的Open函数
    较详细的介绍JNI
    Java多线程单元测试
    sleep函数的简单原理
    Struts与Servlet的冲突
    Ant学习记录
    JDK转码工具
    Throwable
    Entity Framework系列文章导航
    多核时代 .NET Framework 4 中的并行编程1概述
  • 原文地址:https://www.cnblogs.com/DE_LIU/p/7481747.html
Copyright © 2011-2022 走看看