指令碼建立分割槽表

2021-09-11 08:51:27 字數 3871 閱讀 8173

#!/bin/bash

#確保提供的sql檔名與sql中的表名一致

#使用指令碼之前先在/home/mysql/opdir/zfy/新建乙個目錄例如:mkdir 20171215/sql

#把業務方提供的sql語句放在sql資料夾中

if

[ $# != 2 ];then

echo usage: $0 zk_port database

exit 1

filet zk_port=

$1database=

$2mysql_port=

$(($zk_port-

901))

let menu_port=

$(($zk_port-

4001

))date=

`date +%y%m%d`if[

! -d /home/mysql/opdir/zfy/$/sql ]

;then

echo error:/home/mysql/opdir/zfy/$/sql directory not exist!

exit 1

fifile_sql=/home/mysql/opdir/zfy/$/sqlcd$

if[$?!= 0 ]

;then

echo into current directory fail

exit 1

fi#獲取所有檔名稱

mkdir -p /home/mysql/opdir/zfy/$/tmp_`

date +%y%m%d`

tmp_dir=/home/mysql/opdir/zfy/$/tmp_`

date +%y%m%d`

for i in

`ls ./`;do

echo$i|

awk -f'.'

''>>

$/$_all_table_name.txt

if[$?

!= 0 ]

;then

echo gets the file name error

exit 1

fidone

#改名tablet

for i in

`ls ./`

;do

name=

`echo $i |

awk -f'.'''`

;sed -i "s/$/$__tablet_/g"

$iif[$?

!= 0 ]

;then

echo change tablet_name error

exit 1

fidone

#合並且換行

for i in

`ls ./`;do

cat$i

>>

$_all_table.sql

echo

>>

$_all_table.sql

if[$?

!= 0 ]

;then

echo merge file error

exit 1

fidone

#複製四份

for i in

`seq 0 3`;do

cp$_all_table.sql $_all_table_$i.sql

if[$?

!= 0 ]

;then

echo copy file 4 fail

exit 1

fidone

#改名稱

for i in

`seq 0 3`;do

sed -i 's/tablet_/tablet_'

$i'/g'

$_all_table_$i.sql

if[$?

!= 0 ]

;then

echo modify the name fail

exit 1

fidone

#獲取zk資訊cd$

if[$?!= 0 ]

;then

echo into current directory fail

exit 1

fimkdir ./zk_cache

cd ./zk_cache

for i in

`cat

../$_all_table_name.txt`;do

cp /home/mysql/opdir/zfy/zk_template.conf $i.conf

if[$?

!= 0 ]

;then

echo get zk information error

exit 1

fidone

#替換每個檔案的表名

for i in

`ls ./`

;do

name=

`echo $i|

awk -f'.'''`

sed -i "s/aaaaa/$/g"

$iif[$?

!= 0 ]

;then

echo replace table name fail

exit 1

fidone

#合併到乙個檔案

for i in

`ls ./`;do

cat$i

>> zk_cache.conf

if[$?

!= 0 ]

;then

echo combine fail

exit 1

fidone

#追加到zk配置檔案中

cp /home/mysql/menu/menu$/conf/zk_cache.baixin.conf /home/mysql/menu/menu$/conf/zk_cache.baixin.conf.bak.$

sed -i "4 r $tmp_dir/zk_cache/zk_cache.conf" /home/mysql/menu/menu$/conf/zk_cache.baixin.conf

if[$?

!= 0 ]

;then

echo error: add to zk_cache.baixin.conf fail!

exit 1

fiif[

$?= 0 ]

;then

echo dbproxy create successful

rm -rf /home/mysql/opdir/zfy/$/tmp_`

date +%y%m%d`

else

echo table create failed

exit 1

fi#把表導入庫cd$

~/mysql_3100/bin/mysql --defaults-file=~/mysql_$/etc/user.root.cnf --default-character-set=utf8 -a -e "use $;source $_all_table_1.sql;source $_all_table_3.sql;"

#建立完成重啟menu

/home/mysql/menu/menu$/bin/service.sh stop && /home/mysql/menu/menu$/bin/service.sh startif[

$?= 0 ]

;then

echo -e "\033[32m menu restart done \033[0m"

else

echo -e "\033[31m menu restart faild \033[0m"

echo check /home/mysql/menu/menu$/conf/zk_cache.baixin.conf

exit 1

fi

Oracle 建立分割槽表

建立表空間 create tablespace mytablespace 1 datafile c oracle product 10.1.0 oradata mydata mytablespace1.dbf size 100m extent management local uniform siz...

hive 建立分割槽表

必須在表定義時建立partition a 單分割槽建表語句 create table day table id int,content string partitioned by dt string 單分割槽表,按天分割槽,在表結構中存在id,content,dt三列。以dt為資料夾區分 b 雙分割...

Oracle 建立分割槽表

建立表空間 create tablespace mytablespace 1 datafile c oracle product 10.1.0 oradata mydata mytablespace1.dbf size 100m extent management local uniform siz...