http://www.mysqlinfo.com/2011/11/08/%E6%B5%8B%E8%AF%95mysql%E6%95%B0%E6%8D%AE%E5%BA%93%E5%BA%93%E5%90%8D%E5%92%8C%E8%A1%A8%E5%90%8D%E6%9C%80%E5%A4%A7%E5%85%81%E8%AE%B8%E9%95%BF%E5%BA%A6/
#!/bin/bash # made by zhoubo # counter_dbname_long.sh mysql=`which mysql` counter=0 a="b" $mysql -Ne "create database t_"$a while [ $? -eq 0 ] do a=$a"b" (( counter++ )) mysql -Ne "create database t_"$a &>/dev/null done expr $counter + 2 mysql -A -Bse "show databases;" ¦ grep t_b* ¦xargs -t -I '{}' mysql -e "drop database "{}";" &> /dev/null 19:04 [[email protected]]$ sh counter_dbname_long.sh 64 #!/bin/bash # made by zhoubo # counter_tbname_long.sh mysql=`which mysql` counter=0 a="b" $mysql -Ne "use test;create table t_"$a" (id int(1));" while [ $? -eq 0 ] do a=$a"b" (( counter++ )) $mysql -Ne "use test;create table t_"$a" (id int(1));" 2>/dev/null done expr $counter + 2 mysql -A -Bse "use test;show tables" ¦ grep t_b* ¦xargs -t -I '{}' mysql -A -Bse "use test;drop table "{}";" &> /dev/null
19:04 [[email protected]]$ sh counter_tbname_long.sh 64