MySQL backup shell script for all databases in Linux

Source: Internet
Author: User
Tags mkdir mysql backup

All databases to one file:

The code is as follows Copy Code

#!/bin/bash

date=$ (date + '%y%m%d ')
to_dir= "/home/wyl/document/Daily/230_database"
Date_dir=${to_dir} "/" ${date}

Hostname= ' 192.168.1.230 '
Username= ' Root '
Password= ' Tianji '

if [!-d "$DATE _dir"]; Then
mkdir $DATE _dir
Fi
Mysqldump--no-data-h$hostname-u$username-p$password--all-databases > $DATE _dir/all_database.sql

A single database to a single file:

  code is as follows copy code

#!/bin/bash
  
date=$ (DATE + '%y%m%d ')
to_dir="/home/ wyl/Document/Daily/230_database "
Date_dir=${to_dir}"/"${date}
  
hostname= ' 192.168.1.230 '
Username= ' root '
password= ' Tianji '
  
If [!-d "$DATE _dir"]; then
    &NB sp;   mkdir $DATE _dir
Fi
mysql-h$hostname-u$username-p$password-e "show databases like '%9e% '" |sed ' 1d ' |while read line
do
        mysqldump--no-data-h$hostname-u$username- P$password $LINE > $DATE _dir/$LINE. SQL
Done

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.