Use MySQL database mysqldump to implement automatic backup

Source: Internet
Author: User
Tags mysql database backup

Use the MySQL database mysqldump tool, can realize the database backup function, if in the Linux system Configuration good crontabs, can realize the automatic backup!

#!/bin/bash

# #配置原数据库连接信息, that is, using a database machine that needs to be backed up.

Source_user=-uroot

# #如果就是在本机ip, that source_host=-h127.0.0.1

source_host=-h10.10.10.12

Source_pass=-padministrator

# #配置备份数据库的连接信息, the database machine for backup

Bak_user=-uroot

# #用于备份的数据库机器ip

bak_host=-h10.10.10.22

Bak_pass=-padministrator

# #从原数据库中导出数据库表的内容, and generate SQL files, station for database names, username and files for table names

/var/mysql/bin/mysqldump--add-drop-table--opt $SOURCE _user $SOURCE _host $SOURCE _pass Station username >/tmp/ Username.sql

/var/mysql/bin/mysqldump--add-drop-table--opt $SOURCE _user $SOURCE _host $SOURCE _pass station files >/tmp/ Files.sql

# #导入到备份的数据库中

/var/mysql/bin/mysql $BAK _user $BAK _host $BAK _pass Station </tmp/username.sql

/var/mysql/bin/mysql $BAK _user $BAK _host $BAK _pass Station </tmp/files.sql

Related Article

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.