ITPub博客

首页 > 数据库 > MySQL > MYSQL常见表操作

MYSQL常见表操作

原创 MySQL 作者:Jane_Hoo 时间:2015-02-02 19:02:05 0 删除 编辑


>check table 表名;                      //检查表
>analyze table …;
>repair table …;
>optimize table …;
>flush table表名;                     //刷新表
>alter table…;
>rename table ..;            #修改表名
>Rename  table  basicinfo  to  basic;                //将表名由basicinfo修改为basic
>Alter  table  basic rename to basicinfo;         //将表名由basic 修改为basicinfo
> alter table tbl_name add col col_def after pre_col;
>alter table tbl_name modify col col_def
>Alter  table  basic  engine = innodb ;             // 更改存储引擎
> Alter table basic default charset=utf8;        //更改默认字符集:
>Alter table basicinfo convert to character set gbk;                      //在线转换,可能会丢失部分信息,导致数据无法正常显示
> describe tbl_name;
>truncate 表名;               //清空表
                                     #索引操作
>create index idx_colname on tbl_name(col)
>show index from tbl_name;
>drop index idx_colname on tbl_name;
>alter table tbl_name add index idx_colname(col);
快捷建表:
>Create  table newtbl engine=innodb default charset=utf8 select * from oldtbl;
        { 如果两个表的存储引擎相同,默认这两个表的结构和数据会是一样,当时如果,这两张表的存储引擎不同,那么他们的数据会相同,列名相同但是各列之间的关系却不能复制 }
但如果使用:
>Create  table  newtbl  like  oldtbl;
>Insert  into  newtbl select  *  from  oldtbl;
        { 就目前的实验来看,可以避免上述问题 }

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30126478/viewspace-1424183/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-02-02

  • 博文量
    11
  • 访问量
    19972