gpt4 book ai didi

mysql - 如何转储 MySQL 中每个表的 DESC(csv 格式)

转载 作者:行者123 更新时间:2023-11-29 02:37:55 24 4
gpt4 key购买 nike

我需要为数据库中的几百个表生成 DESC TableName 的 CSV 文件。

你们能帮我解决一下吗?我确信有一种使用 Bash 脚本的方法。我尝试使用 mysqldump 但它用于结构的数据转储和 sql 转储:(

谢谢!

最佳答案

从 MySQL 5.0 开始,您可以使用 information_schema ( http://dev.mysql.com/doc/refman/5.0/en/information-schema.html )

例子:

SELECT      CASE ordinal_position 
WHEN 1 THEN CONCAT('Table ', table_schema, '.', table_name, '\n')
ELSE ''
END
, column_name
, column_type
, is_nullable
, column_key
, column_default
, extra
FROM information_schema.columns
WHERE table_schema = SCHEMA()
ORDER BY table_schema
, table_name
, ordinal_position

此处的输出应该与您从 DESC 获得的输出相同(但不相同)

请注意,在这种情况下,查询仅报告当前数据库中的表。调整 WHERE 子句以满足您的要求。

还有一个警告:这些查询可能非常慢,尤其是。如果他们第一次运行。

关于mysql - 如何转储 MySQL 中每个表的 DESC(csv 格式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2149739/

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