#!/bin/bash

# 将sql文件上传到mysql的目录 /var/lib/docker/mysql-pv
# 修改目录的权限为


export local_mysql_host_path="/var/lib/docker/mysql-pv/$sql_file_folder_name"
export sql_file_folder_name=2.1
chown 1001:1001 /var/lib/docker/mysql-pv/xakny/${sql_file_folder_name}/


mysql -uk8s_admin -p'fP#UaH6qQ3)8' -h127.0.0.1 -P3306 <


('developer','$2a$10$qJxo2SgRS8OADjLoxATj3uG3dXcJ7Pq.R4zw0iPXIVueJlZhTsitO',1)
('nacos','$2a$10$UjG7QDzn43yRkgB/Vor/TOXns7K60F3Btuy3bKfq2.oodsqFX9Sn.',1)

# 然后执行mysql的pod
export sql_file_folder_name=6.2
export sql_import_file_path="/bitnami/mysql/${sql_file_folder_name}"
for sql_file in $(ls "$sql_import_file_path" | sort -n -k1.1,1.2); do
    echo "current file is ${sql_file}"

    # 本地mysql执行
    mysql -uroot -pQzfXQhd3bQ -h127.0.0.1 -P3306 <"$sql_import_file_path/${sql_file}"
    echo "------------------"
    echo ""
done

INSERT INTO `uav_lifecycle`.`regulator` (`id`, `name`, `is_system_admin`, `telephone`, `avatar_url`, `authentication_status`, `authentication_time`, `password`, `password_modify_time`, `is_frozen`, `is_del`, `create_at`, `create_by`, `update_at`, `update_by`) VALUES (1, '超级管理员', b'1', LOWER(HEX(AES_ENCRYPT('13800000000','TELEPHONE'))), NULL, 0, NULL, '$2a$10$zaAxaqvNzx8HdERMTrOF6u.InuKLSSi2VGQDBmYuEIG56ZqV6TwBu', NOW(), b'0', b'0', NOW(), 'r_1', NOW(), 'r_1');


# doris初始化
mysql -uroot -hdoris-cluster-fe-internal -P9030 < 1node_table_init.sql

# nacos备份
## 在pod里面执行
mysqldump  -uroot -pQzfXQhd3bQ -h127.0.0.1 -P3306 -t --set-gtid-purged=OFF cmii_nacos_config config_info his_config_info roles users > ${sql_import_file_path}/cmii_nacos_config_wdd.sql
sed -i '1s/^/use cmii_nacos_config;\n/' ${sql_import_file_path}/cmii_nacos_config_wdd.sql


## 在主机上执行
cp ${local_mysql_host_path}/cmii_nacos_config_wdd.sql /root/wdd/install/cmii_nacos_config_wdd.sql


# 传统的版本
 https://oss.demo.uavcmlc.com/cmlc-installation/downloadfile/amd/mysql-8.0.27-linux-glibc2.17-x86_64-minimal.zip


    # dev
#     /root/wdd/mysql/bin/mysql -uroot -pGwubc6CxRM -h192.168.35.178 -P33306 <"$sql_import_file_path/${sql_file}"
    # devflight
#     /root/wdd/mysql/bin/mysql -uroot -pGwubc6CxRM -h192.168.35.178 -P33307 <"$sql_import_file_path/${sql_file}"
    # devoperation
    # /root/wdd/mysql/bin/mysql -uroot -pGwubc6CxRM -h192.168.35.178 -P33308 <"$sql_import_file_path/${sql_file}"
    # chongqing san hua
#      /root/wdd/mysql/bin/mysql -uroot -pQzfXQhd3bQ -h36.133.115.164 -P53309  <"$sql_import_file_path/${sql_file}"

# 江西移动升级

/root/wdd/mysql-8.0.27-linux-glibc2.17-x86_64-minimal/bin/mysql -uroot -pQzfXQhd3bQ -h127.0.0.1 -P33306  < new_schema.sql