MySQL
  Home arrow MySQL arrow Page 3 - Backing Up Your MySQL Databases With MySQL...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Backing Up Your MySQL Databases With MySQLDump
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 92
    2002-01-30

    Table of Contents:
  • Backing Up Your MySQL Databases With MySQLDump
  • The mysqldump utility
  • More examples

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Backing Up Your MySQL Databases With MySQLDump - More examples


    (Page 3 of 3 )

    Example 2:

    mysqldump --opt mydatabase > sql.dump

    Specifying the --opt argument when backing up our database should theoretically give us the fastest possible dump for reading back into MySQL server (the "opt" stands for optimize). When we specify the --opt argument, the mysqldump utility creates a more sophisticated set of dump commands, which includes the "DROP TABLE IF EXISTS" statement to delete the table from the database if it already exists when the dump file is being used to restore the database. The dump also includes several table locking statements.

    Here's a sample of the sql.dump file that was generated when I backed up the same database with the –-opt argument:

    #

    # Table structure for table 'tbl_contactemails'

    #

    DROP TABLE IF EXISTS tbl_contactemails;

    CREATE TABLE tbl_contactemails (

    pk_ceId int(11) NOT NULL auto_increment,

    ceEmail varchar(250) NOT NULL default '',

    ceType int(11) default NULL,

    PRIMARY KEY (pk_ceId),

    UNIQUE KEY id (pk_ceId)

    ) TYPE=MyISAM;

    #

    # Dumping data for table 'tbl_contactemails'

    #

    LOCK TABLES tbl_contactemails WRITE;

    INSERT INTO tbl_contactemails VALUES (18,'mitchell@devarticles.com',1),(17,'mitchell_harper@hotmail.com',1),(16,'mytch@dingoblue.net.au',1);

    UNLOCK TABLES;


    Example 3:

    mysqldump --opt mydatabase | mysql --host=localhost -C newdatabase

    One excellent feature of the mysqldump utility is that it supports backing up a database from one MySQL server to another with just one command. In the example above, I have chosen to backup the "mydatabase" database to the server named localhost (which is the net bios name of my local machine). I have used the –C argument to tell the mysqldump utility to enforce data compression between my MySQL server and the destination server if they both support it. Lastly, I have specified that all of the tables from the "mydatabase" database should be created in a new database on the remote server named "newdatabase".

    In the example above I have used localhost as the name of the remote MySQL server to send the backup data to. You can replace this with the net bios name of any other computer on your network, or the I.P. address of any local or remote computer if you want to send the database to a MySQL server over your network or the Internet.

    There's one catch to using this method: You must have already created the database on the remote server. In our example we are simply backing up the "mydatabase" database on the same machine, so we would use the following command at the MySQL console application before we ran the mysqldump utility:

    create database newdatabase;
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · this was a good first half and article on backing up a database. I don t use...
     

    MYSQL ARTICLES

    - MySQL and BLOBs
    - Two Lessons in ASP and MySQL
    - Lord Of The Strings Part 2
    - Lord Of The Strings Part 1
    - Importing Data into MySQL with Navicat
    - Building a Sustainable Web Site
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - PhpED 3.2 – More Features Than You Can Poke ...
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - Security and Sessions in PHP
    - Setup Your Personal Reminder System Using PHP
    - Create a IP-Country Database Using PERL and ...
    - Developing a Dynamic Document Search in PHP ...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT