How to Automatically or Manually backup MySQL database?

Posted on 2009-04-17
Last Modified: 2012-05-06
I am looking for a way to backup a MySQL database.  

Current Method:  Using PHPMYADMIN I export all tables from 'HACW_V2' to the screen.  I cut and paste the Statements to a WORD document and save.    I also have the option to save as a file.  

Goal:  Be able to backup database automatically (by whatever means you can think of), or create a link on my intranet home page that will create a backup and save it to a predetermined (or manually specified location) with only one click.  

Tools:  I currently use PHP for my intranet site.  My web server was compiled by XAMPP.

thanks for any help you are able to give.
Question by:drews77
    LVL 107

    Expert Comment

    by:Ray Paseur
    LVL 21

    Assisted Solution

    - Using mysql-administrator Gui tool
    - Using mysqldump
    - Directly copying datafiles

    - If you want to make it a real simple script then:
    On linux/unix system:
    #create an sh file with following line and put it in a crontab:
    mysql -uroot -pPASSWORD --databases DATABASE-NAME > DATABASE_`date +%d_%m_%y`.sql

    Now about your goal: following may help as well--
    LVL 6

    Accepted Solution

    If you use their gui tools it lets you specify the dates to do backups and stuff like that under MySQL Administrator:
    LVL 14

    Assisted Solution


    Here is an automatic backup script:

    Here is a simple script to do this:

    $dbname = '*';
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = '';
    $backupFile = 'back' . date("Y-m-d-H-i-s") . '.gz';
    $command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile";

    Hope this will help you.


    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
    Creating and Managing Databases with phpMyAdmin in cPanel.
    The viewer will learn how to dynamically set the form action using jQuery.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now