I have a exported sql schema file. (similar to what we have here 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.
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. That would require a SQL parser capable of reading the .sql script format. This is implemented in MySQL using a combination of the mysql
client and the MySQL Server SQL parser. 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. Then you could dump the data in CSV format, or whatever other format you want.
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.
Another alternative is to use mysqldump --tab
to dump CSV files. I'll encourage you read the documentation about that.