Saturday, May 1, 2010

MySqldump

Hi friends,

If you find Mysqldump on google you will find lots of website to create dump file, backup file from existing one or more databases of mysql and restore it.

Best link is,

http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html


I want to just write a little bit thing that I searched lot.

That when we generate dump - sql - backup file from mysql, uses command

shell>> mysqldump -u uname -p dbname > dbfile.sql

That will back complete database to dbfile.sql

When on reverse, if I tried to restore that database from dbfile.sql

on Windows it works using same mysqldump

c://MySql//bin> mysqldump dbname < dbfile.sql

Just difference of < and >

while the same thing in linux not works
It will purform and shows output as below

-- MySQL dump 10.11
--
-- Host: localhost Database: royaleducation
-- ------------------------------------------------------
-- Server version 5.0.51a-3ubuntu5.5

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
/*!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 */;

-- Dump completed on 2010-05-01 13:02:48


It says Dump completed but when we goto that perticular database and show tables
It will give 0 tables there in database.
for linux we have to use mysql command

shell>> mysql -u root -p dbname < dffile.sql

That will works well.

but for that required to create database first in mysql.

2 comments:

Ketan Rajeshbhai Bhavsar said...

Add on in this MySqlDump.

If we require to dump just one table at that time <> <> required like,

mysqldump -u uname -p dbname myTable > dbfile.sql

Ketan Rajeshbhai Bhavsar said...

One more thing to addon here

Dump is very necessary if database backup of innodB type if we want database backup and it's type of MySql then just copy of .frm, .myd, .myi is enough.

If database contains .ibd and .frm that means table is in innodB type.