#同时删除表名类似的多张表
#参数1是数据库名 参数2传表名
#!/bin/sh
if [ $# -ne 2 ];then
echo "input argument dbname universaltablename"
exit 1;
fi
mysqlConnect='mysql'
droptable=`$mysqlConnect -e "SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' )
AS statement FROM information_schema.tables WHERE table_schema = '$1' AND table_name LIKE '$2%';" | grep -v statement`
#注意使用~键中的那个点,将删除表的命令复制给droptable_sql变量
echo $droptable; #打印要删除所有表
$mysqlConnect -e"use $1;${droptable}" #执行删除命令
#参数1是数据库名 参数2传表名
#!/bin/sh
if [ $# -ne 2 ];then
echo "input argument dbname universaltablename"
exit 1;
fi
mysqlConnect='mysql'
droptable=`$mysqlConnect -e "SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' )
AS statement FROM information_schema.tables WHERE table_schema = '$1' AND table_name LIKE '$2%';" | grep -v statement`
#注意使用~键中的那个点,将删除表的命令复制给droptable_sql变量
echo $droptable; #打印要删除所有表
$mysqlConnect -e"use $1;${droptable}" #执行删除命令