gpt4 book ai didi

MySql 仅导出架构而不导出数据

转载 作者:行者123 更新时间:2023-11-29 11:26:51 26 4
gpt4 key购买 nike

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

最佳答案

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

操作系统(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';

操作系统(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';

注意:将所需的路径放在INTO OUTFILE之后。

关于MySql 仅导出架构而不导出数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38067541/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com