MySQL第五天
复制表结构
1 #从src_table复制到dst_table
2 CREATE TABLE dst_table LIKE src_table;
3
4 #另外一种方法
5 CREATE TABLE dst_table SELECT * FROM src_table WHERE 0;
6
7 #第一种方法比第二种方法简单实用效率高
8
9
10 #复制表中数据
11 #完全复制src_table
12 CREATE TABLE det_table SELECT * FROM src_table;
13
14 #复制其中两列
15 CREATE TABLE det_table SELECT a,b FROM src_table;
16
17 #也可以先创建表,然后再进行复制
18 SELECT INTO dst_table(a1,b1) SELECT a2,b2 FROM src_table;
19
2 CREATE TABLE dst_table LIKE src_table;
3
4 #另外一种方法
5 CREATE TABLE dst_table SELECT * FROM src_table WHERE 0;
6
7 #第一种方法比第二种方法简单实用效率高
8
9
10 #复制表中数据
11 #完全复制src_table
12 CREATE TABLE det_table SELECT * FROM src_table;
13
14 #复制其中两列
15 CREATE TABLE det_table SELECT a,b FROM src_table;
16
17 #也可以先创建表,然后再进行复制
18 SELECT INTO dst_table(a1,b1) SELECT a2,b2 FROM src_table;
19
查看、更改当前表的引挚
代码
#第一中方法,非常实用,但是很长比较麻烦,
mysql> SELECT ENGINE FROM INFORMATION_SCHEMA.TABLES
-> WHERE TABLE_SCHEMA = 'cookbook' AND TABLE_NAME = 'mail';
+--------+
| ENGINE |
+--------+
| MyISAM |
+--------+
1 row in set (0.00 sec)
#第二种方法
mysql> SHOW TABLE STATUS LIKE 'mail'\G
*************************** 1. row ***************************
Name: mail
Engine: MyISAM
Version: 10
Row_format: Fixed
Rows: 16
Avg_row_length: 73
Data_length: 1168
Max_data_length: 20547673299877887
Index_length: 2048
Data_free: 0
Auto_increment: NULL
Create_time: 2010-08-12 21:50:25
Update_time: 2010-08-12 21:50:25
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
#第三种方法
mysql> SHOW CREATE TABLE mail \G
*************************** 1. row ***************************
Table: mail
Create Table: CREATE TABLE `mail` (
`t` datetime DEFAULT NULL,
`srcuser` char(8) CHARACTER SET latin1 DEFAULT NULL,
`srchost` char(20) CHARACTER SET latin1 DEFAULT NULL,
`dstuser` char(8) CHARACTER SET latin1 DEFAULT NULL,
`dsthost` char(20) CHARACTER SET latin1 DEFAULT NULL,
`size` bigint(20) DEFAULT NULL,
KEY `t` (`t`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
#修改表的引挚,但是修改会非常耗资源,小心
#把表mail的引挚修改为InnoDB
mysql> ALTER TABLE mail ENGINE = InnoDB;
Query OK, 16 rows affected (0.02 sec)
Records: 16 Duplicates: 0 Warnings: 0
mysql> SELECT ENGINE FROM INFORMATION_SCHEMA.TABLES
-> WHERE TABLE_SCHEMA = 'cookbook' AND TABLE_NAME = 'mail';
+--------+
| ENGINE |
+--------+
| MyISAM |
+--------+
1 row in set (0.00 sec)
#第二种方法
mysql> SHOW TABLE STATUS LIKE 'mail'\G
*************************** 1. row ***************************
Name: mail
Engine: MyISAM
Version: 10
Row_format: Fixed
Rows: 16
Avg_row_length: 73
Data_length: 1168
Max_data_length: 20547673299877887
Index_length: 2048
Data_free: 0
Auto_increment: NULL
Create_time: 2010-08-12 21:50:25
Update_time: 2010-08-12 21:50:25
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
#第三种方法
mysql> SHOW CREATE TABLE mail \G
*************************** 1. row ***************************
Table: mail
Create Table: CREATE TABLE `mail` (
`t` datetime DEFAULT NULL,
`srcuser` char(8) CHARACTER SET latin1 DEFAULT NULL,
`srchost` char(20) CHARACTER SET latin1 DEFAULT NULL,
`dstuser` char(8) CHARACTER SET latin1 DEFAULT NULL,
`dsthost` char(20) CHARACTER SET latin1 DEFAULT NULL,
`size` bigint(20) DEFAULT NULL,
KEY `t` (`t`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
#修改表的引挚,但是修改会非常耗资源,小心
#把表mail的引挚修改为InnoDB
mysql> ALTER TABLE mail ENGINE = InnoDB;
Query OK, 16 rows affected (0.02 sec)
Records: 16 Duplicates: 0 Warnings: 0
转载保留链接