简体   繁体   English

如何从 sql 模式文件中提取数据?

[英]How to extract data from a sql schema file?

I have a exported sql schema file.我有一个导出的 sql 模式文件。 (similar to what we have here https://livesql.oracle.com/apex/livesql/file/content_O5AEB2HE08PYEPTGCFLZU9YCV.html ) (类似于我们这里的 https://livesql.oracle.com/apex/livesql/file/content_O5AEB2HE08PYEPTGCFLZU9YCV.html

This file is having all Create table and insert values commands.该文件包含所有创建表和插入值命令。

I want to export all the database to a CSV or JSON format.我想将所有数据库导出为 CSV 或 JSON 格式。

Is there a way to achieve the same?有没有办法达到同样的目的?

You appear to be asking how to convert the data from the.sql script directly to a raw data format.您似乎在询问如何将数据从 .sql 脚本直接转换为原始数据格式。 That would require a SQL parser capable of reading the.sql script format.这将需要一个能够读取 .sql 脚本格式的 SQL 解析器。 This is implemented in MySQL using a combination of the mysql client and the MySQL Server SQL parser.这是在 MySQL 中使用mysql客户端和 MySQL 服务器 SQL 解析器的组合实现的。 It would be an awful lot of work to duplicate this.复制这个将需要大量工作。

Honestly, the easiest solution is to use the mysql client to import the.sql script's tables and data into a MySQL instance.老实说,最简单的解决方案是使用mysql客户端将 .sql 脚本的表和数据导入到 MySQL 实例中。 Then you could dump the data in CSV format, or whatever other format you want.然后您可以将数据转储为 CSV 格式,或您想要的任何其他格式。

You can run queries using the mysql client in batch mode to dump results to CSV format (really tab-delimited), or you could write a simple client in Python or whatever your favorite language is.您可以使用mysql客户端以批处理模式运行查询,将结果转储为 CSV 格式(实际上是制表符分隔),或者您可以使用 Python 或您喜欢的任何语言编写一个简单的客户端。

Another alternative is to use mysqldump --tab to dump CSV files.另一种选择是使用mysqldump --tab转储 CSV 个文件。 I'll encourage you read the documentation about that.我鼓励您阅读相关文档。

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

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