#!/bin/bash
MYSQL_USER="xxxxx"
MYSQL_PASSWORD="xxxxx"
TABLES=$(mysql -h 127.0.0.1 -u $MYSQL_USER -p$MYSQL_PASSWORD -e "SELECT databasesi from company_xxxxxx.tenant_data_temp;")
for DB in $TABLES; do
echo "Executing SQL in $DB"
mysql -h 127.0.0.1 -u $MYSQL_USER -p$MYSQL_PASSWORD $DB -e "insert into company_xxxxxx.t_data_test select '$DB',count(id) from t_admin_user where last_login_time is not null;"
done
从临时表里面查出数据名
然后循环跨库查询,查询出来的结果再插入一张临时表存储