MySql 总结

一、数据库管理:  

    1.查看数据库      mysql>show databases;   

    2.创建数据库      mysql>create database 数据库名;  

    3.使用数据库      mysql>use 数据库名;   

    4.删除数据库      mysql>drop database 数据库名;

二、数据表管理:   

    1.查看数据库表      mysql>show tables;       

    2.查看数据表结构      mysql>desc 数据库表名;      mysql>show create table 表名G;   

    3.创建数据库表      mysql>create table 数据库表名 (列名   类型   修饰符);  

    4.删除数据库表      mysql>drop table 数据库表名;   

    5.修改,添加,删除,字段改名,字段排列顺序,更改表名:     

      mysql>alter table 表名 modify 需要修改的字段 修改的类型;   

      mysql>alter table 表名 add 需要添加的新字段名 字段类型;     

      mysql>alter table 表名 drop 需要删除的字段名;    

      mysql>alter table 表名 change 原来的字段名 新的字段名 新的字段类型;    

      mysql>alter table 表名 modify|add| 字段名 字段类型 first|after 字段名;   

      mysql>alter table 原数据表名 rename 新数据表名;  

  6.创建有索引的表     mysql>create index 索引名 on 表名 (列表);     

     或者      mysql>create table 表名 (index index1 (id,name));    

  7.插入数据      mysql>insert into 表名 (列表名)            values(要插入的数据);   

     或者      mysql>insert into 表名 set 列表1=数据,列表2=数据;   

  8.更新数据      mysql>update 表名 set 列名1=数据1,列名2=数据2,...[where clause];       

  9.删除数据      mysql>delete from 表名 [where clause];   

  10.查询数据      mysql>select 列名1,列名2 from 表名1,表名2 [where clause];

原文地址:https://www.cnblogs.com/dingding0505/p/3382162.html