最近有个需求,在mysql数据库中每个月建自动一个表,把该月的数据存储到该月对应的表中。
一、创建存储过程
期望表名:
login_history_2017_07(login_history_YYYY_MM)
字段:
id (int(11) primary key auto_increment)
uid (char(10) not null)
ip (char(200) not null)
DELIMITER //
create procedure create_login_history_table()
begin
set @tbCreate = concat('create table ','login_history_',date_format(now(),'%YYYY_%mm'),"(
id int(11)