shell批量插入mysql表数据
#!/bin/bash
#set -ex 此处不能打开,不然无法执行sum++ ,跟告警提示有关?
HOSTNAME="192.168.133.129"
PORT="3306"
USERNAME="root"
PASSWORD="123456@123"
DBNAME="cloud_games_shelves"
#TABLENAME="test_table_test"
sum=0
for i in {1..72};do
for x in {1..7};do
insert_db_sql="INSERT INTO cloud_games_shelves.t_area_access_point_info (aapid, area_type, online_state, mgr_state, company_ipv4_address, company_ipv4_state, inner_ipv4_address, outer_ipv6_address, outer_ipv4_address, raw_ipv4_address, create_time, update_time, modify_time) VALUES ($sum, $x, 1, $x, '1', 0, '192.168.10.144', '111', '188.88.88.1', '', '2023-05-19 16:10:16', '2023-05-19 16:10:16', '2023-05-19 16:10:16');"
mysql -h${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} -e "${insert_db_sql}"
let sum++
done
done
#for ((i=4 ; i<504 ; i++));do
# insert_db_sql="INSERT INTO cloud_games_shelves.t_area_access_point_info (aapid, area_type, online_state, mgr_state, company_ipv4_address, company_ipv4_state, inner_ipv4_address, outer_ipv6_address, outer_ipv4_address, raw_ipv4_address, create_time, update_time, modify_time) VALUES ($i, $i, 1, 1, '1', 0, '192.168.10.143', '111', '188.88.88.2', '', '2023-05-19 16:10:16', '2023-05-19 16:10:16', '2023-05-19 16:10:16');"
# mysql -h${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD} -e "${insert_db_sql}"
#done
#mysql -h${HOSTNAME} -P${PORT} -u${USERNAME} -p${PASSWORD}<<EOF
#use ${DBNAME}
##下面是sql,注意!可以写多条SQL,但每条sql之间使用;分割
#select * from test_table_test;
#select now();
#create temporary table temp (select * from test_table_test);
#EOF