mysql中如何修改表的名字?修改表名?

需求描述:

  今天在进行mysql表的历史数据迁移,需要将某张表进行备份,修改表的名字,在此记录下操作过程.

操作过程:

mysql> create table ts01 like ti_o_sms;       #创建表结构.这样的建表方式,不仅仅是表的结构,连带着索引也会同时创建.
Query OK, 0 rows affected (0.02 sec)

mysql> alter table ts01 rename to ts01_new;   #修改表名的语法:alter table rename to/as new_tablename;
Query OK, 0 rows affected (0.00 sec)

mysql> show tables;                      
+--------------------+
| Tables_in_mytest   |
+--------------------+
| sms_send_blacklist |
| td_b_sendobject    |
| ti_o_sms           |
| ts01_new           |
+--------------------+
4 rows in set (0.00 sec)

或者

mysql> alter table ts01_new rename AS ts02;
Query OK, 0 rows affected (0.03 sec)

mysql> show tables;
+--------------------+
| Tables_in_mytest   |
+--------------------+
| sms_send_blacklist |
| td_b_sendobject    |
| ti_o_sms           |
| ts02               |
+--------------------+
4 rows in set (0.00 sec

备注:表名已经成功的进行修改.

 

官方文档修改表名的语法:

mysql> help alter table
Name: 'ALTER TABLE'
Description:
Syntax:
ALTER TABLE tbl_name
    [alter_specification [, alter_specification] ...]
    [partition_options]

alter_specification:
    table_options
.......| RENAME [TO|AS] new_tbl_name

.......

 

文档创建时间:2018年8月20日17:08:13

posted @ 2018-08-20 17:10  Zhai_David  阅读(131977)  评论(1编辑  收藏  举报