By using mysqldump client program we can take the backup of a database into a file having the extension ‘.sql’. it can be understood with the help of following example −
Example
In this example, with the help of mysqldump client program, we are taking the backup of a database named ‘tutorials’ in a file named ‘tutorials.sql’. The following command will do this −
C:\mysql\bin>mysqldump -u root tutorials > tutorials.sql
The above command will create a file named ‘turorials.sql’ in the bin folder of MySQL. This file will contain drop table, create a table and insert command for all the tables in the tutorials database. Following is a partial output of tutorials.sql showing the dump information of ‘rtgs’ table −
-- -- Table structure for table `rtgs` -- DROP TABLE IF EXISTS `rtgs`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `rtgs` ( `id` int(11) DEFAULT NULL, `name` varchar(20) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `rtgs` -- LOCK TABLES `rtgs` WRITE; /*!40000 ALTER TABLE `rtgs` DISABLE KEYS */; INSERT INTO `rtgs` VALUES (1,'Ram'),(2,'Shyam'); /*!40000 ALTER TABLE `rtgs` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;