#在工作中, there is often a need to create n-tables with the name of time or number. #下面给出4种常用的批量创建100张表的小脚本. #结果mysql > show tables;+-----------------+| tables_in_tsdb |+-----------------+| total_winner_01 | | total_winner_02 | | total_winner_03 | | total_winner_04 | | total_winner_05 | | total_winner_06 | | total_winner_07 | | total_winner_08 | | total_winner_09 | | total_winner_10 | | total_winner_11 | | total_winner_12 | | total_winner_13 | | total_winner_14 | | total_winner_15 |+-----------------+15 rows in set (0.00 sec) #第一种: # #create 100 tables#!/bin/sh#db_name= ' Use renmaiinfluencedb ' for i in {0 99};d o len= ' expr length $i ' if [ $len - eq 2 ];then num= $ielse num= "0${i}" Fi echo ' create table ' total_winner_ ' "$num" ( ' Id ' INT (10 ), ' UserId ' INT (, primary key (' Id ')) ENGINE = innodb default charset = utf8 ; ' echo done============= =========================================================================================== #第二种: #!/bin/sh# creat tablesfor i in ' seq 1 15 ' do var= ' printf '%02d\ N " $i ' echo ' create table ' Total_winner_" $var " ( ' Id ' INT (), ' UserId ' INT (Ten), primary KEY (' Id ')) ENGINE = INNODB DEFAULT CHARSET = utf8 ; ' echodone============================================================ ================ #第三种: #!/bin/sh # need to remove the " " symbol from SQL for i in ' seq 0 1 99 ' do step= ' printf %02d ${i} ' create_tab_sql= ' create table total_winner_${step} ( Id INT ), userid int (, primary key (Id)) engine = innodb default charset = utf8 ; " echo -e ${create_tab_sql} echodone=================================================================================== #第四种: Python script #!/usr /bin/pythonimport stringfor i in range (7,13): sql = " create table ' content_2015%02d ' LIKE ' content_201503 '; " % i print (SQL) For i in range (15,20): sql = "CREATE TABLE  ' content_2016%02d ' LIKE ' content_201503 '; " % i print (SQL) ========================================
This article is from "Drunken Breeze" blog, please be sure to keep this source http://11805203.blog.51cto.com/11795203/1833412
Create 100 sheets in bulk