1. bat

    mysql跑库

    @echo offchcp 65001%~d0cd %~dp0set basepath=%~dp0set | findstr mysqlif "%ERRORLEVEL%" == "0" ( goto paraminit) ELSE ECHO THERE IS NOT MYSQL ENV !goto end:paraminitset /p mysqlhost="ip 地址,默认值 ==> (127.0.0.1) : "set /p mysqlport="请输出mysql服务端口,默认值 ==> (3306) :"set /p rootpwd="请输出mysql超管明码,默认值 ==> (root) :"set /p kupwd="请输出oneaccess各个库拥有者对应的明码,默认值 ==> (Bamboocloud@1234) : "set /p suffix="请输出oneaccess对应的库及用户的后缀,默认为空串: "if "%mysqlhost%"=="" set mysqlhost=127.0.0.1if "%mysqlport%"=="" set mysqlport=3306if "%rootpwd%"=="" set rootpwd=rootif "%kupwd%"=="" set kupwd=Bamboocloud@1234if "%suffix%"=="" set suffix=set sql_dir=sql_cmd_executermdir /s/q %basepath%\%sql_dir%mkdir -p %basepath%\%sql_dir% xcopy /y/e/i %basepath%\bam %basepath%\%sql_dir% xcopy /y/e/i %basepath%\bim %basepath%\%sql_dir% xcopy /y/e/i %basepath%\epass %basepath%\%sql_dir% xcopy /y/e/i %basepath%\apphub %basepath%\%sql_dir% goto replacepwdfohcs:replacepwdfohcs@setlocal enabledelayedexpansionfor /f "delims=" %%i in (%basepath%\%sql_dir%\bam_mysql_db_create.sql) do (set content=%%iset content=!content:bam_password=abcdefghijklmnopqrst!set content=!content:bam=bam%suffix%!set content=!content:abcdefghijklmnopqrst=%kupwd%!echo !content!>>$1)move $1 %basepath%\%sql_dir%\bam_mysql_db_create.sql || EXIT \Bfor /f "delims=" %%i in (%basepath%\%sql_dir%\bim_mysql_db_create.sql) do (set content=%%iset content=!content:bim_password=abcdefghijklmnopqrst!set content=!content:bim=bim%suffix%!set content=!content:abcdefghijklmnopqrst=%kupwd%!echo !content!>>$2)move $2 %basepath%\%sql_dir%\bim_mysql_db_create.sql || EXIT \Bfor /f "delims=" %%i in (%basepath%\%sql_dir%\apphub_mysql_db_create.sql) do (set content=%%iset content=!content:apphub_password=abcdefghijklmnopqrst!set content=!content:apphub=apphub%suffix%!set content=!content:abcdefghijklmnopqrst=%kupwd%!echo !content!>>$3)move $3 %basepath%\%sql_dir%\apphub_mysql_db_create.sql || EXIT \Bfor /f "delims=" %%i in (%basepath%\%sql_dir%\epass_mysql_db_create.sql) do (set content=%%iset content=!content:epass_password=abcdefghijklmnopqrst!set content=!content:epass=epass%suffix%!set content=!content:abcdefghijklmnopqrst=%kupwd%!echo !content!>>$4)move $4 %basepath%\%sql_dir%\epass_mysql_db_create.sql || EXIT \Bgoto mysqlsqlexec:mysqlsqlexecset _timeTemp=0call:GetTimeSeconds %time%set time1=%_timeTemp%rem choice  期待5秒 再计算另外一个工夫点 mysql -h %mysqlhost% -uroot -p%rootpwd% -P %mysqlport% -D "mysql" <  %basepath%\%sql_dir%\bam_mysql_db_create.sql -vvv mysql -h %mysqlhost% -uroot -p%rootpwd% -P %mysqlport% -D "mysql" <  %basepath%\%sql_dir%\bim_mysql_db_create.sql -vvv mysql -h %mysqlhost% -uroot -p%rootpwd% -P %mysqlport% -D "mysql" <  %basepath%\%sql_dir%\apphub_mysql_db_create.sql -vvv mysql -h %mysqlhost% -uroot -p%rootpwd% -P %mysqlport% -D "mysql" <  %basepath%\%sql_dir%\epass_mysql_db_create.sql -vvv mysql -h %mysqlhost% -uroot -p%rootpwd% -P %mysqlport% -D "bam%suffix%" <  %basepath%\%sql_dir%\bam\bam_mysql_table_and_data.sql -vvv mysql -h %mysqlhost% -uroot -p%rootpwd% -P %mysqlport% -D "bim%suffix%" <  %basepath%\%sql_dir%\bim_mysql_table_and_data.sql -vvv mysql -h %mysqlhost% -uroot -p%rootpwd% -P %mysqlport% -D "apphub%suffix%" <  %basepath%\%sql_dir%\apphub_mysql_table_and_data.sql -vvv mysql -h %mysqlhost% -uroot -p%rootpwd% -P %mysqlport% -D "epass%suffix%" <  %basepath%\%sql_dir%\epass_mysql_table_and_data.sql -vvv@echo off@REM "goto printexetimes:printexetimescall:GetTimeSeconds %time%set time2=%_timeTemp%set /a interTime=%time2% - %time1%echo echo 已全量跑库实现 hcs_mysql_bat 耗时: %interTime% 秒 !!goto end:GetTimeSecondsset tt=%1rem windows下%time%工夫的格局个别为hour:minute:second.number 上面两行只是去掉冒号和顿号变成hour minute second number ,此处只是取hour minute secondset tt=%tt:.= %set tt=%tt::= %set index=1for %%a in (%tt%) do ( if !index! EQU 1 (     set hh=%%a )^ else if  !index! EQU 2 (     set mm=%%a  )^ else if  !index! EQU 3 (     set ss=%%a )set /a index=index+1)set /a _timeTemp=(%hh%*60+%mm%)*60+%ss%goto:end:end

    mysql删库

    @echo offchcp 65001set | findstr mysqlif "%ERRORLEVEL%" == "0" (goto paraminit)echo there is no mysql envgoto end:paraminitset /p mysqlhost="请输出ip:"set /p mysqlport=请输出端口set /p rootpwd=请输出明码set /p suffix=请输出后缀if "%mysqlhost%"=="" set mysqlhost=127.0.0.1if "%mysqlport%"=="" set mysqlport=3306if "%rootpwd%"=="" set rootpwd=rootif "%suffix%"=="" set suffix=136goto mysqldelexec:mysqldelexecmysql -h %mysqlhost% -uroot -p%rootpwd% -P %mysqlport% -e "use mysql;DROP USER IF EXISTS 'bam%suffix%'@'%%';DROP USER IF EXISTS 'bam%suffix%'@'localhost';DROP DATABASE IF EXISTS `bam%suffix%`;DROP USER IF EXISTS 'bim%suffix%'@'%%';DROP USER IF EXISTS 'bim%suffix%'@'localhost';DROP DATABASE IF EXISTS `bim%suffix%`;DROP USER IF EXISTS 'apphub%suffix%'@'%%';DROP USER IF EXISTS 'apphub%suffix%'@'localhost';DROP DATABASE IF EXISTS `apphub%suffix%`;DROP USER IF EXISTS 'epass%suffix%'@'%%';DROP USER IF EXISTS 'epass%suffix%'@'localhost';DROP DATABASE IF EXISTS `epass%suffix%`;" -vvvgoto end:endpause
  2. bash

    mysql跑库

    #!/bin/bashset -oe#-u为数据库用户名 -p为明码如果数据库明码不是root记得批改这里read -p "ip 地址,默认值 ==> (127.0.0.1) : " mysqlhostread -p "请输出mysql服务端口,默认值 ==> (3306) : " mysqlportread -p "请输出mysql超管明码,默认值 ==> (root) : " rootpwdread -p "请输出oneaccess各个库拥有者对应的明码,默认值 ==> (Bamboocloud@1234) : " kupwdread -p $'\033[40;32m 请输出oneaccess对应的库及用户的后缀,默认为空串: \033[0m' suffixstarttime=`date +'%Y-%m-%d %H:%M:%S'`suffix=${suffix:-""}rootpwd=${rootpwd:-"root"}mysqlport=${mysqlport:-"3306"}mysqlhost=${mysqlhost:-"127.0.0.1"}kupwd=${kupwd:-"Bamboocloud@1234"}basepath=$( cd $(dirname $0) pwd)rm -rf ${basepath}/sql_executemkdir -p ${basepath}/sql_execute\cp -r ${basepath}/{bam,bim,apphub,epass} ${basepath}/sql_executesed -i "s/bam_password/kupwd/g" ${basepath}/sql_execute/bam/bam_mysql_db_create.sqlsed -i "s/bam/bam${suffix}/g" ${basepath}/sql_execute/bam/bam_mysql_db_create.sqlsed -i "s/kupwd/${kupwd}/g" ${basepath}/sql_execute/bam/bam_mysql_db_create.sqlsed -i "s/bim_password/kupwd/g" ${basepath}/sql_execute/bim/bim_mysql_db_create.sqlsed -i "s/bim/bim${suffix}/g" ${basepath}/sql_execute/bim/bim_mysql_db_create.sqlsed -i "s/kupwd/${kupwd}/g" ${basepath}/sql_execute/bim/bim_mysql_db_create.sqlsed -i "s/epass_password/kupwd/g" ${basepath}/sql_execute/epass/epass_mysql_db_create.sqlsed -i "s/epass/epass${suffix}/g" ${basepath}/sql_execute/epass/epass_mysql_db_create.sqlsed -i "s/kupwd/${kupwd}/g" ${basepath}/sql_execute/epass/epass_mysql_db_create.sqlsed -i "s/apphub_password/kupwd/g" ${basepath}/sql_execute/apphub/apphub_mysql_db_create.sqlsed -i "s/apphub/apphub${suffix}/g" ${basepath}/sql_execute/apphub/apphub_mysql_db_create.sqlsed -i "s/kupwd/${kupwd}/g" ${basepath}/sql_execute/apphub/apphub_mysql_db_create.sqlmysql -h$mysqlhost -uroot -p$rootpwd -P$mysqlport -e \"use mysql;source ${basepath}/sql_execute/bam/bam_mysql_db_create.sql;  source ${basepath}/sql_execute/bim/bim_mysql_db_create.sql; source ${basepath}/sql_execute/apphub/apphub_mysql_db_create.sql;source ${basepath}/sql_execute/epass/epass_mysql_db_create.sql; use bam${suffix}; source ${basepath}/sql_execute/bam/bam_mysql_table_and_data.sql; use bim${suffix}; source ${basepath}/sql_execute/bim/bim_mysql_table_and_data.sql; use apphub${suffix}; source ${basepath}/sql_execute/apphub/apphub_mysql_table_and_data.sql; use epass${suffix}; source ${basepath}/sql_execute/epass/epass_mysql_table_and_data.sql;" -vvvendtime=`date +'%Y-%m-%d %H:%M:%S'`start_seconds=$(date --date="$starttime" +%s);end_seconds=$(date --date="$endtime" +%s);echoecho "运行 hcs-mysql 跑库脚本......"echoecho "====================hcs============================"echo "开始工夫:" $starttimeecho "完结工夫:" $endtimeecho "本次跑库耗时: "$((end_seconds-start_seconds))"s"echo "====================hcs============================"

mysql删库

#!/bin/bash#-u为数据库用户名 -p为明码如果数据库明码不是root记得批改这里read -p "ip 地址,默认值 ==> (127.0.0.1) : " mysqlhostread -p "请输出mysql服务端口,默认值 ==> (3306) : " mysqlportread -p "请输出mysql超管明码,默认值 ==> (root) : " rootpwdread -p $'\033[40;32m 请输出须要删除oneaccess对应的库及用户的后缀,默认为空串: \033[0m' suffixsuffix=${suffix:-""}rootpwd=${rootpwd:-"root"}mysqlport=${mysqlport:-"3306"}mysqlhost=${mysqlhost:-"127.0.0.1"}mysql -h$mysqlhost -uroot -p$rootpwd -P$mysqlport -e \    "use mysql;DROP USER IF EXISTS 'bam${suffix}'@'%';DROP USER IF EXISTS 'bam${suffix}'@'localhost';DROP DATABASE IF EXISTS \`bam${suffix}\`;DROP USER IF EXISTS 'bim${suffix}'@'%';DROP USER IF EXISTS 'bim${suffix}'@'localhost';DROP DATABASE IF EXISTS \`bim${suffix}\`;DROP USER IF EXISTS 'apphub${suffix}'@'%';DROP USER IF EXISTS 'apphub${suffix}'@'localhost';DROP DATABASE IF EXISTS \`apphub${suffix}\`;DROP USER IF EXISTS 'epass${suffix}'@'%';DROP USER IF EXISTS 'epass${suffix}'@'localhost';DROP DATABASE IF EXISTS \`epass${suffix}\`;" -vvv
  1. dm/shell

跑库

#!/bin/bash#==============================================================## 脚本名     :   hcs_dm_initall.sql# 创立工夫   :   2022-12-28 10:02:09# 更新工夫   :   2022-12-29 10:30:18# 形容      :   应用脚本,依据输出的后缀不同 一键跑完DM的数据库脚本# 门路      :   需与oneaccess dm版本的sql目录在同一门路下# 版本      :   1.0.0# 作者      :   dongjelababy(18271632505@163.com)# Copyright (C) 2021-2022 HCS#==============================================================##==============================================================##                         HCS_DM                              ##==============================================================## 获取达梦的装置目录dmdispwd=$(find / -path *bin/disql | head -1)read -p "请输出dm服务端口,默认值 ==> (5236) : " dmportread -p "请输出dm超管明码,默认值 ==> (SYSDBA) : " sysdbapwdread -p "请输出oneaccess各个库拥有者对应的明码,默认值 ==> (Bamboocloud@1234) : " kupwdread -p "请输出oneaccess对应的库及用户的后缀,默认为空串: " suffixsuffix=${suffix:-""}sysdbapwd=${sysdbapwd:-"SYSDBA"}dmport=${dmport:-"5236"}kupwd=${kupwd:-"Bamboocloud@1234"}if [ "$suffix" = "" ]; thenread -p "后缀为空,请确认(yes/no):yes持续,no退出" inputinput=$(echo "$input" | tr "[A-Z]" "[a-z]")if [ "$input" = "yes" ]; then   echo "yes go"else echo "exit zero"exitfielse   echo "go"fistarttime=`date +'%Y-%m-%d %H:%M:%S'`dy="'"sy='"'dir=hcs_dm_executerm -rf ./${dir}mkdir ./${dir}# bam cat bam/bam_dm_db_create.sql >./${dir}/bam_dm_db_create.sqlcat >>./${dir}/bam_dm_db_create.sql<<hcsexit;hcscat bam/bam_dm_20.0.2_all.sql >./${dir}/bam_dm_20.0.2_all.sqlcat >>./${dir}/bam_dm_20.0.2_all.sql<<hcsexit;hcs# bimcat bim/bim_dm_db_create.sql >./${dir}/bim_dm_db_create.sqlcat >>./${dir}/bim_dm_db_create.sql<<hcsexit;hcscat bim/bim_dm_table_create.sql >./${dir}/bim_dm_table_create.sqlcat >>./${dir}/bim_dm_table_create.sql<<hcsexit;hcscat bim/business_dm_table_create.sql >./${dir}/business_dm_table_create.sqlcat >>./${dir}/business_dm_table_create.sql<<hcsexit;hcscat bim/bim_dm_trigger.sql >./${dir}/bim_dm_trigger.sqlcat >>./${dir}/bim_dm_trigger.sql<<hcsexit;hcscat bim/bim_dm_data_init.sql >./${dir}/bim_dm_data_init.sqlcat >>./${dir}/bim_dm_data_init.sql<<hcsexit;hcscat bim/business_dm_data_init.sql >./${dir}/business_dm_data_init.sqlcat >>./${dir}/business_dm_data_init.sql<<hcsexit;hcs# epasscat epass/epass_dm_db_create.sql >./${dir}/epass_dm_db_create.sqlcat >>./${dir}/epass_dm_db_create.sql<<hcsexit;hcscat epass/epass_dm_20.0.2_all.sql >./${dir}/epass_dm_20.0.2_all.sqlcat >>./${dir}/epass_dm_20.0.2_all.sql<<hcsexit;hcs# apphubcat apphub/apphub_dm_db_create.sql >./${dir}/apphub_dm_db_create.sqlcat >>./${dir}/apphub_dm_db_create.sql<<hcsexit;hcscat apphub/apphub_dm_table_create.sql >./${dir}/apphub_dm_table_create.sqlcat >>./${dir}/apphub_dm_table_create.sql<<hcsexit;hcscat apphub/apphub_dm_data_sample.sql >./${dir}/apphub_dm_data_sample.sqlcat >>./${dir}/apphub_dm_data_sample.sql<<hcsexit;hcssed -i "s/Bamboocloud@1234/kupwd/g"  ./${dir}/bam_dm_db_create.sqlsed -i "s/BAM/BAM${suffix}/g" ./${dir}/bam_dm_db_create.sqlsed -i "s/kupwd/${kupwd}/g" ./${dir}/bam_dm_db_create.sqlsed -i "s/Bamboocloud@1234/kupwd/g"  ./${dir}/bim_dm_db_create.sqlsed -i "s/BIM/BIM${suffix}/g" ./${dir}/bim_dm_db_create.sqlsed -i "s/kupwd/${kupwd}/g" ./${dir}/bim_dm_db_create.sqlsed -i "s/Bamboocloud@1234/kupwd/g"  ./${dir}/epass_dm_db_create.sqlsed -i "s/EPASS/EPASS${suffix}/g" ./${dir}/epass_dm_db_create.sqlsed -i "s/kupwd/${kupwd}/g" ./${dir}/epass_dm_db_create.sqlsed -i "s/Bamboocloud@1234/kupwd/g"  ./${dir}/apphub_dm_db_create.sqlsed -i "s/APPHUB/APPHUB${suffix}/g" ./${dir}/apphub_dm_db_create.sqlsed -i "s/kupwd/${kupwd}/g" ./${dir}/apphub_dm_db_create.sql$dmdispwd SYSDBA/"${sysdbapwd}":"${dmport}" \`./${dir}/bam_dm_db_create.sql$dmdispwd SYSDBA/"${sysdbapwd}":"${dmport}" \`./${dir}/bim_dm_db_create.sql$dmdispwd SYSDBA/"${sysdbapwd}":"${dmport}" \`./${dir}/epass_dm_db_create.sql$dmdispwd SYSDBA/"${sysdbapwd}":"${dmport}" \`./${dir}/apphub_dm_db_create.sql# bam 跑库表eval "$dmdispwd BAM${suffix}/$dy$sy${kupwd}$sy$dy:${dmport} \\\`./${dir}/bam_dm_20.0.2_all.sql"# bim 跑库表eval "$dmdispwd BIM${suffix}/$dy$sy${kupwd}$sy$dy:${dmport} \\\`./${dir}/bim_dm_table_create.sql"eval "$dmdispwd BIM${suffix}/$dy$sy${kupwd}$sy$dy:${dmport} \\\`./${dir}/business_dm_table_create.sql"eval "$dmdispwd BIM${suffix}/$dy$sy${kupwd}$sy$dy:${dmport} \\\`./${dir}/bim_dm_trigger.sql"eval "$dmdispwd BIM${suffix}/$dy$sy${kupwd}$sy$dy:${dmport} \\\`./${dir}/bim_dm_data_init.sql"eval "$dmdispwd BIM${suffix}/$dy$sy${kupwd}$sy$dy:${dmport} \\\`./${dir}/business_dm_data_init.sql"# epass跑库表eval "$dmdispwd EPASS${suffix}/$dy$sy${kupwd}$sy$dy:${dmport} \\\`./${dir}/epass_dm_20.0.2_all.sql"# apphub跑库表eval "$dmdispwd APPHUB${suffix}/$dy$sy${kupwd}$sy$dy:${dmport} \\\`./${dir}/apphub_dm_table_create.sql"eval "$dmdispwd APPHUB${suffix}/$dy$sy${kupwd}$sy$dy:${dmport} \\\`./${dir}/apphub_dm_data_sample.sql"endtime=`date +'%Y-%m-%d %H:%M:%S'`start_seconds=$(date --date="$starttime" +%s);end_seconds=$(date --date="$endtime" +%s);echoecho echoecho "====================hcs============================"echo "开始工夫:" $starttimeecho "完结工夫:" $endtimeecho "本次跑库耗时: "$((end_seconds-start_seconds))"s"echo "====================hcs============================"

删库

#!/bin/bash#==============================================================## 脚本名     :   hcs_dm_destroyall.sh# 创立工夫   :   2022-12-28 10:02:09# 更新工夫   :   2022-12-29 10:30:18# 形容      :   应用脚本,依据输出的后缀不同 一键删除dm数据库的表空间和表# 门路      :   需与oneaccess dm版本的sql目录在同一门路下# 版本      :   1.0.0# 作者      :   dongjelababy(18271632505@163.com)# Copyright (C) 2021-2022 HCS#==============================================================##==============================================================##                         HCS_DM                              ##==============================================================## 获取达梦的装置目录dmdispwd=$(find / -path *bin/disql | head -1)read -p "请输出dm服务端口,默认值 ==> (5236) : " dmportread -p "请输出dm超管明码,默认值 ==> (SYSDBA) : " sysdbapwdread -p "请输出须要删除的oneaccess库及用户的后缀,默认为空串: " suffixsuffix=${suffix:-""}sysdbapwd=${sysdbapwd:-"SYSDBA"}dmport=${dmport:-"5236"}if [ "$suffix" = "" ]; then    read -p "后缀为空,请确认是否删除(yes/no):" input    input=$(echo "$input" | tr "[A-Z]" "[a-z]")    if [ "$input" = "yes" ]; then        echo "yes go"    else        exit    fielse    echo go!fi$dmdispwd SYSDBA/${sysdbapwd}:${dmport} -e "drop user bam${suffix} cascade;"$dmdispwd SYSDBA/${sysdbapwd}:${dmport} -e "drop TABLESPACE bam${suffix};"$dmdispwd SYSDBA/${sysdbapwd}:${dmport} -e "drop user bim${suffix} cascade;"$dmdispwd SYSDBA/${sysdbapwd}:${dmport} -e "drop TABLESPACE bim${suffix};"$dmdispwd SYSDBA/${sysdbapwd}:${dmport} -e "drop user epass${suffix} cascade;"$dmdispwd SYSDBA/${sysdbapwd}:${dmport} -e "drop TABLESPACE epass${suffix};"$dmdispwd SYSDBA/${sysdbapwd}:${dmport} -e "drop user apphub${suffix} cascade;"$dmdispwd SYSDBA/${sysdbapwd}:${dmport} -e "drop TABLESPACE apphub${suffix};"# $dmdispwd SYSDBA/${sysdbapwd}:${dmport} -e <<eof# drop user bam${suffix} cascade;# drop tablespace bam${suffix};# eof