1、MySQL 命令行客户端命令
   mysql -u root -p  (创建用户时候用这个登录)
    Enter the password:   show databases;-- 查看数据库
    show tables; -- 查看表
    use test;  --使用test数据库
  
    SQL  Structured Query Language 结构化查询语言(所有数据库通用,不同的是,不同数据库有不同的函数);2、数据定义语音(DDL)
 
 
    Data Definition Language  如create 创建drop删除 alter修改  对表结构的修改就是数据定义语言 (是表一级的)
    create  database  dname;
    create table  teacher(
     tid int(11) primary key auto_increment  COMMENT '老师编号 ',
     name varchar(20) COMMENT '老师姓名 ',
     gender char(1) COMMENT '老师性别 ',
     age int(2) COMMENT '老师年龄 ',
     birth date COMMENT '老师生日'
    );
    desc tname;查看表结构
    属性之间用  空格隔开
    drop table;
    注明:COMMENT 是对表字段的描述的一个字段属性    修改表
    alter table 表名 add column name varchar(10); 添加一列
    alter tbale teacher rename teacher_tab; 表重命名
    alter table tecaher_tab drop column birth; 删除列
    alter table teacher_tab add column createDate date; 增加列   alter table test modify address char(10) ==修改某一列的类型 只改类型
    alter table test change address add char(40) --修改表列类型名字
    alter table test change column address add char(50) --同上
    
    3、数据操纵语言(DML)
    DATA Manipulation Language (这是表数据一级的,数据操作语言,顾名思义就是操纵数据的)
    Insert ,update ,delete   insert into 表名(字段1,2,3)values(1,2,4)
    
    update表名Set字段名='值',字段名='值' where 字段名="值"
    update table set id=1 where id=0
    update table set id=1,gender=m where id = 0  (注意改第二个改不成功,因为id改了,改第二个字段就找不到了)   delete from table  (全删,谨慎使用)
    delete from table where ....id=1,>1,<1,>=1,<=等符号都能用   
    4 DRL (Data Retrieval Language) 数据库查询语言
   
  1)查询所有信息
   
    select * from tablename;  //* 是通配符,实际工作中,避免使用* 因为* = 所有字段 2)在没有表被引用的情况下,允许您指定一个DUAL 作为一个假的表名。DUAL是mysql中的虚拟表。
    select 1+1from dual ;
   
     mysql> select 1-1 from dual;
 +-----+
 | 1-1 |
 +-----+
 |   0 |
 +-----+  3)查询Id为n的信息
   select * from tablename where id = n;
 4)查询一个字段是空的信息
  select * from tablename where id is null
  id=null是会报错的,数据库会当null是字符串,而且缺少‘’号
  select * from tablename where is not null
 5)使用别名,查询
  select XXX as mmm from tablename where id = 1
 6)两个并列条件
   select * from tbn where id =1 and ... 7)查询id>5的
   select * from tbn where id >5
  
  8)or的用法  select * from tbn where id =1 or ...
  
  9)模糊查询(例如最后一个字母s的)  select * from tbn where name like '%s';//%是通配符
  
  10)查询姓名以制定字符开头的
   
   select * from tbn where name lke 'c%';// 11)查询包含某个字母的姓名
   
   select * from  tbn where name like '%w%' 12)排序
  select * from tbn where ...order by inputDate desc;(降序,从大到小)
 13)多个条件排序
  select * from tbn where ..order by inpuDate desc,age;//年龄升序,时间降序
 14)分组
  select * from tbn where ...group by gender 按性别分组
  查询并统计不同性别的人数  
   select gender,count(gender) from tbn group by gender; 15)分完组以后的条件(分组以后的查询条件,where是分组之前)
select gender,count(gender) from tbn group by gender having  gender='m'
   
  注意上面这种写法效率很低,应该避免使用select gender,count(gender) from tbn where gender=m; 比上面效率高。 
 16)查询记录数
 select count(*) from tbn;
  select count(id) from tbn; select count(id) as c from tbalename tbn;
  
  select ,t.age from tablename t; 17 )limit 使用(分页技术必用技术)
 select * from tbn limit 0 ,3
五。事务控制语言(TCL)
 事务控制语言(Transaction Control Language--TCL)事务控制语言
  COMMIT,ROLLBACK
  事务:(Transaction) 是访问并可能更新数据库中各种数据项的一个程序执行单元(unit).
  例如去银行取款,需要,先进银行,插卡取钱等步骤。 在关系数据库中,一个事务可以是一条SQL语句,一组SQL语句或者整个程序。
 事务应该具有4个熟悉:原子性(atomicity):不能再分的最小单元,就是一些sql语句一个整体,不能再分。
  一致性(consistency),隔离性(isolation):事务和事务之间是隔离的,持续性(durability):事务开始事务结束是持续的。
  ACID特性。设置默认事务提交方式
 set autocommit = false -设置事务提交方式为“手动提交”
  set autocommit = true -设置事务提交方式是“自动提交” 事务就是对数据库的多步操作,要么一起成功,要么一起失败
 commit --手动提交事务
  rollback;--回顾事务
  savepoint point2 --保存还原点
  rollback to point2;--回滚到还原点 没有提交commit 的时候可以回滚,commit以后回滚不了啦就。。。。