Exporting Specific Tables in MySQL Using mysqldump
The other day we needed to restore a single table from a database for our testing environment. Thankfully, MySQL provides an easy solution to this problem.
One of the command line tools that come with MySQL is mysqldump
which is used to generate a dump file of a database. It outputs a series of SQL statements that can then be used to restore the database.
In the most basic form, it’s run like the following.
This will create a file named “whole.sql” that will contain the entire contents of the “database_name” database.
Then when we need to restore the database we can use the mysql
function.
If we want to export a specific table we can specify the table names as the last arguments to the mysqldump
function.
This will only export table_name1 and table_name2 and it can be restored the same way.
Scott Keck-Warren
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around the house with his loving partner.
Top Posts
- Working With Soft Deletes in Laravel (By Example)
- Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
- Upgrading to Laravel 8.x
- Get The Count of the Number of Users in an AD Group
- Multiple Vagrant VMs in One Vagrantfile
- Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
- Changing the Directory Vagrant Stores the VMs In
- Accepting Android SDK Licenses From The OSX Command Line
- Fixing the 'Target class [config] does not exist' Error
- Using Rectangle to Manage MacOS Windows