在mysql中如何复制表结构
时间:2019-08-20 17:58:08 来源:igfitidea点击:
如何只mysql中表的结构,不复制表数据。
使用命令create table 新表 like 旧表
完成
登录mysql服务器
mysql -u username -p
列出MySQL server中的数据库,选择其中一个进行连接
mysql > show databases; mysql > use 数据库名 ;
列出数据库中所有的表,并创建一个新的复制表
mysql > show tables mysql > create table 新表 like 旧表 ;
示例
mysql> use store; Database changed mysql> show tables; +-----------------------+ | Tables_in_store | +-----------------------+ | st_categories | | st_config | | st_files | | st_rating | +-----------------------+ 4 rows in set (0.00 sec) mysql> desc st_config; +---------------+--------------+------+-----+---------------+-------+ | Field | Type | Null | Key | Default | Extra | +---------------+--------------+------+-----+---------------+-------+ | name | varchar(225) | YES | | NULL | | | news | varchar(225) | NO | | Welcome! | | | vids_per_page | int(4) | NO | | 10 | | | lang | varchar(225) | NO | | en-gb.inc.php | | | version | double | NO | | NULL | | | template | varchar(255) | NO | | Photine | | +---------------+--------------+------+-----+---------------+-------+ 6 rows in set (0.00 sec) mysql> create table st_config_new like st_config; Query OK, 0 rows affected (0.16 sec) mysql> desc st_config_new; +---------------+--------------+------+-----+---------------+-------+ | Field | Type | Null | Key | Default | Extra | +---------------+--------------+------+-----+---------------+-------+ | name | varchar(225) | YES | | NULL | | | news | varchar(225) | NO | | Welcome! | | | vids_per_page | int(4) | NO | | 10 | | | lang | varchar(225) | NO | | en-gb.inc.php | | | version | double | NO | | NULL | | | template | varchar(255) | NO | | Photine | | +---------------+--------------+------+-----+---------------+-------+ 6 rows in set (0.00 sec) mysql>