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
If we want to export a specific table we can specify the table names as the last arguments to the
This will only export table_name1 and table_name2 and it can be restored the same way.
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.