MySQL Tutorial - How to take backup of single table from a database on MySQL Server by using mysqldump

Scenario:


Often as DBAs have to run delete, update or insert statements on a table, it is always good idea to take the backup of a table before running any DML statements. Below syntax can be used to take the backup of a table in MySQL Server. mysqldump will  create the file which will have drop table, create table and then insert statements for each line. If your table is huge, it can take long time to take the backup and also restore can be lengthy process.

Syntax:

mysqldump --user=username --password=ProvidePassword --lock-tables DatabaseName TableName > /tmp/FileName.sql

Example:

If I have a database name TechBrothers and one of the table is Emp that I need to take backup in tmp direcotry, I can use below script.
mysqldump --user=root --password=PasswordforRoot --lock-tables DBA Emp > /tmp/Emp.sql
In above example, I have used root user, you can use the any user which has permission to take backup. 


MySQL DBA Tutorial - Take backup of single table from MySQL Server Database

2 comments: