溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

mysql表結構的復制方法

發(fā)布時間:2021-07-22 09:25:19 來源:億速云 閱讀:344 作者:chen 欄目:MySQL數據庫

本篇內容主要講解“mysql表結構的復制方法”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“mysql表結構的復制方法”吧!

我們特別是oracle dbas常常會通過ctas來復制表結構,這樣復制出來的表實際上會丟掉表的一些屬性,索引就更不說了,在mysql中這樣來復制表其實得到的也只是表大體結構而已。

還好mysql提供了create table like命令方便進行表結構的復制,廢話不說了

root@mysql 02:55:17>use test
Database changed
root@test 03:25:22>create table t1(a int,b int,key (a)) engine=myisam;
Query OK, 0 rows affected (0.00 sec)

root@test 03:25:49>show create table t1G
*************************** 1. row ***************************
Table: t1
Create Table: CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
KEY `a` (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk
1 row in set (0.00 sec)

root@test 03:25:55>create table t2 as select * from t1 where 1=0;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0

root@test 03:26:16>show create table t2G
*************************** 1. row ***************************
Table: t2
Create Table: CREATE TABLE `t2` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=gbk
1 row in set (0.00 sec)

root@test 03:26:25>create table t3 like t1;
Query OK, 0 rows affected (0.00 sec)

root@test 03:26:44>show create table t3G
*************************** 1. row ***************************
Table: t3
Create Table: CREATE TABLE `t3` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL,
KEY `a` (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk
1 row in set (0.00 sec)

到此,相信大家對“mysql表結構的復制方法”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續(xù)學習!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI