How does mysql automatically back up the database? _ MySQL

Source: Internet
Author: User
How does mysql automatically back up databases in windows:
Specifically, if you need to use the Task Scheduler to run automatically, perform the following steps:

1. click Start, select "program"> "attachment"> "system tools"> "task Plan" (or "set"> "control panel"> "task Plan "), start the task scheduler management program for Windows 2000.

2. in the "Task Scheduler" window, double-click the "Add Task Scheduler" icon to start the "Task Scheduler wizard" of the system, and then click the "next" button, select the application to be automatically run in the program list, and click "next.
Set the appropriate task plan name and select the time frequency for automatic execution of the task (such as daily, weekly, monthly, one-time, every start of the computer, and every login time ), click "next.
At this time, the system will require the user to set the specific time for the program to run, such as the number, the number of minutes, and the time period to run. we only need to set the time according to our own needs.

4. the system will ask the user to set the appropriate user name and password (as shown in figure 5) so that the system can run automatically in the future.

5. finally, you only need to click the "finish" button to add the corresponding task to the task scheduler in Windows 2000. then it will automatically "remember" the task, once the system time and related conditions are consistent with the user-defined plan, it automatically calls the user-specified application, which is very convenient (every time Windows 2000 is started, the task scheduler will be automatically started and run in the background to ensure that your plans can be executed on time ).

Now let's test whether the task we just created is successful. right-click the "php" program icon (6) and select "run" in the pop-up menu ". In general, the program icon can be started as long as it is activated and running. If the operation fails, check whether the user and password are correctly set, and check whether the "Task Scheduler" service has been started. I turned it off to save system resources, causing the operation to fail, I have been searching for it for a long time. In addition, you can view the cause of the failure in the system log.

Now we have discussed the application of such a multi-task plan. here are two examples:

1. run PHP regularly!
1. edit the following code and save it as test. php:
$ Fp = @ fopen ("test.txt", "a + ");
Fwrite ($ fp, date ("Y-m-d H: I: s"). "Let PHP run regularly! /N ");
Fclose ($ fp );
?>

2. add a Task Scheduler. in this step, enter the command: D:/php4/php.exe-q D:/php4/test. php.

3. set the time to run the task once every one minute and then run the task.

4. now let's see if the content in the d:/php4/test.txt file is successful. If the content is as follows, congratulations.

11:08:01 let PHP run on a regular basis!
11:09:02 let PHP run on a regular basis!
11:10:01 let PHP run on a regular basis!
11:11:02 let PHP run on a regular basis!

II. make it possible for MYSQL to implement automatic backup!
1. edit the code below and save it as backup.php. if you want to compress the code, you can copy rar.exe:
If ($ argc! = 2 | in_array ($ argv [1], array ('-- help ','-? '))){
?>
Backup Ver 0.01, for Win95/Win98/WinNT/Win2000/WinXP on i32
Copyright (C) 2000 ptker All rights reserved.
This is free software, and you are welcome to modify and redistribute it
Under the GPL license

PHP Shell script for the backup MySQL database.

Usage:

Can be database name you wowould like to backup.
With the -- help, or -? Options, you can get this help and exit.
} Else {
$ Dbname = $ argv [1];
$ Dump_tool = "c: // mysql // bin // mysqldump ";
$ Rar_tool = "d: // php4 // rar ";
@ Exec ("$ dump_tool -- opt-u user-ppassword $ dbname>./$ dbname. SQL ");
@ Exec ("$ rar_tool a-ag_yyyy_mm_dd_hh_mm mongodbname.rar $ dbname. SQL ");
@ Unlink ("$ dbname. SQL ");
Echo "Backup complete! ";
}
?>

2. add a task scheduler and enter the following command in step (2:
D:/php4/php.exe-q D:/php4/backup. php databasename
3. set the time to run the task once every day and then run the task.
4. an rarfile consisting of the database name and current time will be generated in the d:/php4/directory.

In linux:

MySQL: shell script for automatic database backup in Linux
The programs on Linux server update the MySQL database every day, so they think of writing a shell script, combined with crontab, to regularly back up the database. In fact, it is very simple, mainly using the MySQL mysqldump command.

The script content is as follows:
#! /Bin/sh
# File:/home/mysql/backup. sh
# Database info
DB_NAME = "test"
DB_USER = "username"
DB_PASS = "password"

# Others vars
BIN_DIR = "/usr/local/mysql/bin"
BCK_DIR = "/home/mysql/backup"
DATE = 'date + % F'

# TODO
$ BIN_DIR/mysqldump -- opt-u $ DB_USER-p $ DB_PASS $ DB_NAME | gzip> $ BCK_DIR/db_1_date.gz


Then add the script to the/etc/crontab scheduled task:

01 5 ** 0 mysql/home/mysql/backup. sh

All right, the system will automatically run the backup. sh file to back up the MySQL database at every Sunday.

/Home/www/inc/back

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.