MySQL Shell Table Export Utility

We already discussed how we can use MySQL Shell to dump and load data using a multithreaded process. In this post, we will discuss ways we can export data from a table into different formats.
Table Export Utility
In the global util
object in MySQL Shell, there is a method we can use to export table data to various formats (tab-delimited, comma-delimited, etc.). This method is exportTable()
. The exportTable()
method takes three arguments:
- The table we want to export.
- The path to the file where the data will be saved.
- Am options JSON object (optional)
Running the Utility
Let’s look at a basic command for dumping a table named mysql_shorts.games
.
The output I see in the console is:
As you can see, we get information about the number of rows exported, the data throughput, and the time it took. MySQL Shell even gives us a command to import this table data (we will talk about that utility in an upcoming post).
By default, table data is exported in tab-delimited format, with text not enclosed in quotes ("
). The content of games.txt
looks like the text below.
CSV Dialect
If we want to export the table data in a comma-delimited format, we will use the dialect
option as part of our third argument.
When I run this command, I see the following output in the console.
I like how the example command to import this data now includes the dialect
property.
The content of the file looks like the following:
Commas separate the fields, and the text values are enclosed in quotes ("
).
Filtering Data
We can use the where
option to export a subset of the data in a table. Here is how we can filter the exported data to only include scores less than 80
.
The content of the file games_bad.csv
is:
Wrap Up
The methods to handle multithreaded dumps and loads of data are robust and easy to use. However, there may be a need to export data from a table in a more human-readable format or in a format that can be used by other processes (such as Excel). In this case, the MySQL Shell Table Export Utility may be the best tool for the job. To learn more about the options available, including exporting data to Oracle Cloud Infrastructure, AWS, or Azure storage buckets, check out the Table Export Utility documentation.
Related Entries
- Running External Scripts in MySQL Shell
- Executing System Commands in MySQL Shell
- Getting Help in MySQL Shell
- Sandboxes in MySQL Shell
- Server Upgrade Checks with MySQL Shell
- MySQL Connection Status with MySQL Shell
- Managing MySQL Shell Configuration Options
- Advanced Data Dump with MySQL Shell
- Advanced Data Load with MySQL Shell
- MySQL Shell CLI Integration
- Copy Data Directly To A MySQL Instance With MySQL Shell
- Create an InnoDB Replica Set With MySQL Shell
- Using MySQL Shell to Get MySQL Diagnostic Information
- Customizing The MySQL Shell Prompt
- Extending MySQL Shell with Startup Scripts
- Extending MySQL Shell with Plugins
- Doing a 'Incremental' Dump With MySQL Shell