当前位置:网站首页>Mysqldump backup database

Mysqldump backup database

2022-04-23 18:14:00 The hunter is eating meat

Backup

Backup myBlog database .

myBlog_back.sh:

#!/bin/bash

currentDate=$(date "+%F")
currentTime=$(date "+%Y-%m-%d_%H_%M_%S")

build_dir="/opt/db/myBlog/${currentDate}"

echo ${build_dir}
if [ ! -d "${build_dir}" ]; then
	mkdir -p  ${build_dir}
	echo ' Directory created '
fi

/mysql/bin/mysqldump  --defaults-extra-file="/opt/.mysqldump_myBlog.cnf" myBlog > ${build_dir}/myBlog_${currentTime}.sql
echo " Export succeeded "

.mysqldump_myBlog.cnf:

[client]
host='192.168.0.1'
user=root
##  If the password contains special characters , Must be enclosed in quotation marks , Otherwise, you can omit 
password='root'
port=3306

Restore data

##  Log in to the database 
mysql > mysql -uroot -p 
mysql >       #  Input password 

##  Create database 
mysql > create database `myBlog` default character set utf8 collate utf8_general_ci;

##  Switch database 
mysql > use myBlog; 

##  Import data 
mysql > source /opt/db/myBlog/2021-03-14/myBlog_2021-03-14_21_40_01.sql

版权声明
本文为[The hunter is eating meat]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210611118218.html