简体   繁体   English

如何在MySQL中导出SQL的表结构和数据?

[英]How to export sql a table structure and data in mysql?

phpMyAdmin has a feature called export . phpMyAdmin具有一个称为export的功能。 It will export table structure and its data. 它将导出表结构及其数据。 The output will be something like this: 输出将是这样的:

--
-- Table structure for table `input`
--

CREATE TABLE IF NOT EXISTS `input` (
  `input_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `input_type` varchar(255) COLLATE utf8_general_ci DEFAULT NULL,
  PRIMARY KEY (`input_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=8 ;

--
-- Dumping data for table `input`
--

INSERT INTO `input` (`input_id`, `input_type`) VALUES(1, 'text');
INSERT INTO `input` (`input_id`, `input_type`) VALUES(3, 'textarea');
INSERT INTO `input` (`input_id`, `input_type`) VALUES(5, 'radio');
INSERT INTO `input` (`input_id`, `input_type`) VALUES(6, 'checkbox');
INSERT INTO `input` (`input_id`, `input_type`) VALUES(7, 'number');

From my past questions on this site, I learned I can export the structure of my table with SHOW CREATE TABLE : 从我在该站点上过去的问题中,我了解到可以使用SHOW CREATE TABLE导出表的结构:

SHOW CREATE TABLE  `input`;

Is there any way to export data just like in the example above? 是否可以像上面的示例一样导出数据

Here you go: 干得好:

SELECT CONCAT(
    "INSERT INTO `input` (`input_id`, `input_type`) VALUES(",
    input_id,
    ", '",
    input_type,
    "');"
)
AS data
FROM input

We can use mysqldump to generate insert commands only (for all entries in the table) without DB and Table create commands. 我们可以使用mysqldump仅生成插入命令(针对表中的所有条目),而无需DB和Table创建命令。

mysqldump --no-create-db --no-create-info

For other options, please look here 其他选择, 请看这里

AFAIK, ther is no SQL statement that will allow you to generate INSERTS like that. AFAIK,那不是允许您生成类似INSERTS的SQL语句。

Though, if you are looking for a lazy automated processing, I guess you could dump your data with SELECT INTO OUTFILE , then reload it later with LOAD DATA INFILE . 但是,如果您正在寻找一种懒惰的自动处理方法,我想您可以使用SELECT INTO OUTFILE转储数据,然后稍后使用LOAD DATA INFILE重新加载数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM