备份数据到同一实例下的其他数据库操作

Published on with 0 views and 0 comments

会用到锁,其实也还好,没必要用到就尽量不要用。

#!/bin/sh 

mysql -uroot -p8rKSwodBFkcteU8h 2>/dev/null -e "flush tables with read lock;"

mysql -uroot -p8rKSwodBFkcteU8h 2>/dev/null -e "create database bolo_bak;"

tbname=$(mysql -uroot -p8rKSwodBFkcteU8h 2>/dev/null -e "SELECT table_name from information_schema.tables where TABLE_SCHEMA='bolo'")
for i in $tbname; do
    mysql -uroot -p8rKSwodBFkcteU8h bolo_bak 2>/dev/null -e "create table $i like bolo.$i"
    mysql -uroot -p8rKSwodBFkcteU8h hellodb_bak 2>/dev/null -e "insert into $i select * from bolo.$i"
done

mysql -uroot -p8rKSwodBFkcteU8h bolo_bak 2>/dev/null -e "unlock tables;"

标题:备份数据到同一实例下的其他数据库操作
作者:cuijianzhe
地址:https://cjzshilong.cn/articles/2021/09/01/1630476736907.html