Batch create log table information scripts in MySQL

Source: Internet
Author: User

Batch create log table information scripts in MySQL

The script for creating log tables in batches in MySQL is as follows:

Drop PROCEDURE if EXISTS reqSp;
DELIMITER //
Create procedure reqSp (sTime varchar (32), eTime varchar (32), tchema varchar (32 ))

Begin

Declare sName varchar (128 );
Declare uid varchar (128 );
Declare orderId varchar (128 );
Declare sqlVar varchar (1024 );
Declare rest int;

Set rest = 1;

While rest> 0 do

Set sTime = (select DATE_FORMAT (select ADDDATE (sTime, 1), '% Y % m % D '));
Set sName = CONCAT ('tbl _ resp _ ', sTime );
Set uid = CONCAT ('idx _ id_resp _ ', sTime );
Set orderId = CONCAT ('idx _ order_resp _ ', sTime );

Select count (1) from information_schema.tables where table_name = sName and TABLE_SCHEMA = tchema into @ cnt;
If @ cnt = 0 then

Set sqlVar = CONCAT ('create table', sName,
'(Id varchar (60) not null ,',
'Order varchar (100) not null ,',
'Ads int (10) not null ,',
'Type varchar (60) not null ,',
'Group int (10) not null ,',
'Template int (10) not null ,',
'Banner varchar (100) default null ,',
'App varchar (100) default null ,',
'Create_time datetime not null ,',
'Key', uid, '(uid ),',
'Key', orderId, '(order_id )',
') ENGINE = MyISAM default charset = utf8 ');

Set @ v_s = sqlVar;
Prepare stmt from @ v_s;
EXECUTE stmt;
Deallocate prepare stmt;
End if;

Set rest = DATEDIFF (eTime, sTime );

END while;

End;

//
DELIMITER;

Call reqSp ('20140901', '20160901', 'dbname ')

The start time of the first parameter is 20141001.

The end time of the second parameter is 20151001.

The third parameter is the database name.

-------------------------------------- Split line --------------------------------------

Install MySQL in Ubuntu 14.04

MySQL authoritative guide (original book version 2nd) Clear Chinese scan PDF

Ubuntu 14.04 LTS install LNMP Nginx \ PHP5 (PHP-FPM) \ MySQL

Build a MySQL Master/Slave server in Ubuntu 14.04

Build a highly available distributed MySQL cluster using Ubuntu 12.04 LTS

Install MySQL5.6 and Python-MySQLdb in the source code of Ubuntu 12.04

MySQL-5.5.38 universal binary Installation

-------------------------------------- Split line --------------------------------------

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.