mysql怎么设置表名?

来自:互联网
时间:2020-09-27
阅读:
免费资源网 - https://freexyz.cn/

需求描述:

  今天在进行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   RENAME
免费资源网 - https://freexyz.cn/
返回顶部
顶部