我在mysql数据库中有一个表列表,不需要导出数据,如何将表导出为CSV结构而没有数据,只是结构?
答案 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;'