23
Jul 08

MySQL: Database Dump tricks

:: articles :: by Gilberto Saraiva

Folks,

Let me relate this:

Sometimes when you are dumping a database to another host your connection can down, and you will lost all your job and start again? No, no, no, you can make some tricks to continue where you stopped.

So let me enumarate the tricks:

MySQLDump commands:

  • Use –add-drop-table
    For don’t lose what you already done, you can config dump to don’t drop the table you are transfering.
    Command:
     DOS |  copy code |? 
    1
    --add-drop-table=FALSE
  • Use –no-create-info
    To avoid the creation of the table, you need to set this option as true.
    Command:
     DOS |  copy code |? 
    1
    --no-create-info=TRUE
  • Use –where option
    the –where option will work as a SQL filter for you, so if you have a indexed table you can
    Command:
     DOS |  copy code |? 
    1
    --where="ID > 300"
  • MySQL commands:

  • Use –force
    To avoid a break on the processing if the dump post a SQL that can cause a error, you need to Force to MySQL continue even with a SQL error and it will keep the rest of the process working.
    Command:
     DOS |  copy code |? 
    1
    --force
  • So, now you know what the commands do and can create a full command line like this one:

     DOS |  copy code |? 
    1
    2
    C:\MySQL\Bin>mysqldump -h 10.0.0.1 -u root -p123456 --add-drop-table=FALSE --no-create-info=TRUE --where="ID > 300" MyDatabase MyTable | mysql -h www.mysite.com -u MyWebUser -p123456 --force MyWebDatabase
    3

    Piece of cake, uhm?

    Tags: ,


    Leave a comment