MySql仅导出没有数据的模式

时间:2016-06-28 05:14:49

标签: mysql sql database mariadb

我在mysql数据库中有一个表列表,不需要导出数据,如何将表导出为CSV结构而没有数据,只是结构?

2 个答案:

答案 0 :(得分:1)

您可以通过以下查询来完成此操作:

<强>操作系统(Windows):

SELECT 
TABLE_NAME,
GROUP_CONCAT(COLUMN_NAME)
FROM information_schema.COLUMNS 
WHERE TABLE_SCHEMA = 'YOUR_DATABASE_NAME'
GROUP BY TABLE_NAME
INTO OUTFILE 'D:/tableColumnHeaders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';

<强> OS(Linux)的

SELECT 
TABLE_NAME,
GROUP_CONCAT(COLUMN_NAME)
FROM information_schema.COLUMNS 
WHERE TABLE_SCHEMA = 'YOUR_DATABASE_NAME'
GROUP BY TABLE_NAME
INTO OUTFILE '/tmp/tableColumnHeaders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';

注意:path之后放置您想要的INTO OUTFILE

答案 1 :(得分:0)

SHOW CREATE TABLE是重建CREATE TABLE语句的简单方法:

mysql -e 'show create table dbname.tablename;'