Home > Database > Mysql Tutorial > body text

整库备份mysql_MySQL

WBOY
Release: 2016-06-01 13:51:12
Original
814 people have browsed it

我们经常要对数据库做备份,库里面有好几个schema,挺麻烦的,写个脚本,嗯,方便

目前的用户名,密码,host都是写死在脚本里,这样比较方便,有需要的朋友可以把他改成读参数的,

或者是windows风格的下一步

#!/bin/basht=`date +%Y%m%d_%H%M`p_user=rootp_pwd=123456p_host=127.0.0.1#从数据库中读出表结构echo 'select  SCHEMA_NAME  from SCHEMATA ' > sql#p_all_db=(gzcore gzchar gzrealmd gzshop)p_all_db=(`mysql -h${p_host} -u${p_user} -p${p_pwd} information_schema < sql`)rm sql#如果文件夹存在则删除#[[ -d ${p_host} ]] || rm -rf ${p_host}#创建新文件夹mkdir ${p_host} 2>/dev/nullcd ${p_host}#生成for i in ${p_all_db[*]}do    if [ "SCHEMA_NAME" = $i ] || [ "information_schema" = $i ] || [ "mysql" = $i ];then    echo "skip ${p_host} $i"     continue  else    echo "bak ${p_host} $i .."    rm -f ${PWD}/${i}_${t}.dump 2>/dev/null    mysqldump -u${p_user} -p${p_pwd} -h${p_host} --databases $i > ${PWD}/${i}_${t}.dump  fidone#返回原来的路径cd ..
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!