时间:2021-07-01 10:21:17 帮助过:3人阅读
<2>重启MySQL数据库
service mysqld restart
<3>进入数据库命令行模式
创建3个数据库,分别在3个数据库中创建3张表,在表中插入一条数据
create database jfedu;
use jfedu;
create table t1(id varchar(20),name varchar(20));
insert into t1 values("1","daqi");
desc t1;
select * from t1;
注释:
不要忘记验证数据库,表 ,数据是否都已经创建成功
<4>授权一个用于备份数据库的用户名和密码
grant all on *.* to backup@localhost identified by "123456";
<5>
#!/bin/bash #2017年12月6日10:28:54 #by author daqi #mysqldump MySQLDB BAKDIR=/data/backup/mysql/`date +%Y-%m-%d` MYSQLDB=$* MYSQLPW=123456 MYSQLUSR=backup #must use root user run scripts 必须使用root用户运行,$UID为系统变量 if [ $UID -ne 0 ];then echo This script must use the root user ! ! ! sleep 2 exit fi #判断用户输入参数的个数 if [ -z "$1" ];then echo -e "\033[36mPlease Select mysqldump MySQLDB:jfedu|taobao|jd|all\033[0m" exit 0 fi #Define DIR and mkdir DIR 判断目录是否存在,不存在则新建 if [ ! -d $BAKDIR ];then mkdir -p $BAKDIR fi #Use mysqldump backup Databases if [ $1 == "all" ];then /usr/bin/mysqldump -u$MYSQLUSR -p$MYSQLPW --all-databases >$BAKDIR/ALL_DB.sql echo "The $BAKDIR/ALL_DB.sql Mysql Database backup successfully " else for i in `echo $MYSQLDB` do /usr/bin/mysqldump -u$MYSQLUSR -p$MYSQLPW -d $i >$BAKDIR/${i}_db.sql echo "The mysql databases $BAKDIR/${i}_db.sql successfully " done fi |
Shell 脚本备份MySQL数据库
标签:shell mysql mysqldump