您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
#在工作中,经常会有以时间或者数字命名,创建n张表的需求。 #下面给出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}; do len=`expr length $i` if [ $len -eq 2 ];then num=$i else num="0${i}" fi echo ''' CREATE TABLE `Total_Winner_'''$num'''` ( `Id` INT (10), `UserId` INT (10), PRIMARY KEY (`Id`) ) ENGINE = INNODB DEFAULT CHARSET = utf8 ; ''' echo done ======================================================================================================== #第二种: #!/bin/sh #creat tables for i in `seq 1 15` do var=`printf "%02d\n" $i` echo ''' CREATE TABLE `Total_Winner_'''$var'''` ( `Id` INT (10), `UserId` INT (10), PRIMARY KEY (`Id`) ) ENGINE = INNODB DEFAULT CHARSET = utf8 ; ''' echo done ============================================================================ #第三种: #!/bin/sh # 需要将 SQL 中的" ` " 符号删除 for i in `seq 0 1 99` do STEP=`printf %02d ${i}` create_tab_sql=" CREATE TABLE Total_Winner_${STEP} ( Id INT (10), UserId INT (10), PRIMARY KEY (Id) ) ENGINE = INNODB DEFAULT CHARSET = utf8 ;" echo -e ${create_tab_sql} echo done =================================================================================== #第四种:Python脚本 #!/usr/bin/python import string for 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) ========================================
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。