批量建立100張表
#在工作中,經常會有以時間或者數字命名,建立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 ;
dolen=`expr length $i`
if [ $len -eq 2 ];then
num=$i
else
num="0$"
fiecho '''
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`
dovar=`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`
dostep=`printf %02d $`
create_tab_sql="
create table total_winner_$ (
id int (10),
userid int (10),
primary key (id)
) engine = innodb default charset = utf8 ;"
echo -e $
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)
mysql批量建立表
使用儲存過程 delimiter create procedure createtablesinbulk begin declare i int declare table name varchar 200 declare table pre varchar 200 declare sql text...
mysql批量建立表1 500
批量建立表,先寫個函式 詳情看下面 然後執行call 函式名 注意不要忘記寫引數 create definer tequila procedureanno ncbi rel in val s int,in val e int begin declare i int set i val s while...
使用python批量建立 mysql 表
import mysqldb 開啟資料庫連線 這是虛擬機器對映為網路資料庫 db mysqldb.connect 192.168.1.11 hive hive yewu001 port 3306,charset utf8 ip 使用者名稱 密碼 database 埠port 字元編碼 使用curso...