#!/bin/bash

# 导出脚本

SQL_DUMP_FILE=/root/all_tables_4.1.0.sql
./mysql -uroot -pQzfXQhd3bQ -h127.0.0.1 -P33306 -e 'show databases;' | grep -Ev 'Database|information_schema|mysql|sys|performance_schema' | xargs ./mysqldump -uroot -pQzfXQhd3bQ -h127.0.0.1 -P33306 --single-transaction  --source-data=2 --hex-blob --triggers --routines --events --no-data --set-gtid-purged=OFF --databases  > "${SQL_DUMP_FILE}"


SQL_FULL_BACK_UP_FILE=/home/mmc/all_tables_4.0.2_230914_fullback.sql
./mysql -uroot -pQzfXQhd3bQ -h127.0.0.1 -P33306 -e 'show databases;' | grep -Ev 'Database|information_schema|mysql|sys|performance_schema' | xargs ./mysqldump -uroot -pQzfXQhd3bQ -h127.0.0.1 -P33306 --single-transaction  --source-data=2 --hex-blob --triggers --routines --events --set-gtid-purged=OFF --databases  > "${SQL_FULL_BACK_UP_FILE}"

# 被封了nacos_config
./mysqldump -uroot -pQzfXQhd3bQ -h127.0.0.1 -P33306 -t --set-gtid-purged=OFF cmii_nacos_config config_info his_config_info roles users > 17.cmii_nacos_config.sql
sed -i '1s/^/use cmii_nacos_config;\n/' 17.cmii_nacos_config.sql


# 导入脚本
sql_import_file_path=/root/init_5.1.0
for sql_file in $(ls "$sql_import_file_path" | sort -n -k1.1,1.2); do
    echo "current file is ${sql_file}"
    ./mysql -uroot -pQzfXQhd3bQ -h127.0.0.1 -P33306 <"$sql_import_file_path/${sql_file}"
    echo "------------------"
    echo ""
done


#
./mysql -uroot -pQzfXQhd3bQ -h127.0.0.1 -P33306

./mysql -uroot -pQzfXQhd3bQ -h127.0.0.1 -P33306 < /root/init_5.1.0/19


