zoukankan      html  css  js  c++  java
  • perl 通过生成mysql 批量sql

    zabbix:/root/sbin# perl t1.pl  20160101 20160105
    create table test1.test_20160101;
    create table test1.test_20160102;
    create table test1.test_20160103;
    create table test1.test_20160104;
    create table test1.test_20160105;
    create table test2.test_20160101;
    create table test2.test_20160102;
    create table test2.test_20160103;
    create table test2.test_20160104;
    create table test2.test_20160105;
    create table test3.test_20160101;
    create table test3.test_20160102;
    create table test3.test_20160103;
    create table test3.test_20160104;
    create table test3.test_20160105;
    zabbix:/root/sbin# cat t1.pl 
    use DBI;
    use HTTP::Date qw(time2iso str2time time2iso time2isoz);
    my $ip="127.0.0.1";
    my $user="root";
    my $passwd="1234567";
    my $dbh = DBI->connect("dbi:mysql:database=$message;host=$ip;port=3306",$user,$passwd) or die "can't connect to database ". DBI-errstr;
    ##防止utf-8中文乱码
    $dbh->do("SET NAMES utf8");
    my $date1= "$ARGV[0]";
    my $date2="$ARGV[1]";
    my $date=$date1;
    my $tip='+1';
     sub get_date{ 
           my $var_date=$_[0]; 
           my $hostSql = qq{  SELECT DATE_FORMAT( DATE_ADD( '$var_date', INTERVAL $tip  DAY), '%Y%m%d') AS xxx FROM information_schema.tables a limit 1;};
           my ($a1, $a2, $a3,$a4,$a5,$a6,$a7,$a8,$a9);    
           my $selStmt = $dbh->prepare($hostSql);    
           $selStmt->execute();    
           while (@recs=$selStmt->fetchrow_array) {
           foreach (@recs)
           {$date=$_;return $date}
    };
    };
        for ($i=1;$i<=3;$i++){
        while (1==1){
        $date3=$date;
        print "create table test$i.test_$date3;
    ";
        $date=&get_date($date3);
        if ( "$date" == "$date2" ){print "create table test$i.test_$date;
    ";$date="$date1";last;}
       };
       };

  • 相关阅读:
    C#计算某一些任务的执行时间(消耗时间)
    C#打印条码的几种方式
    使用escape编码地址栏中的中文字符
    SQL 批量删除数据表
    弹出层并锁定页面
    后台输出HTML
    C# 十进制与十六进制互转
    SQL判断临时表是否存在
    SQL Server 字符串处理
    Vue文件跳转$router传参数
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349946.html
Copyright © 2011-2022 走看看