create database `ShoppingMallDB` default character set utf8 collate utf8_general_ci;
use ShoppingMallDB;
CREATE TABLE `product_table` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`name` TEXT NULL,
`price` DOUBLE NULL DEFAULT NULL,
`created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=5
;
CREATE TABLE `user_table` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`name` TEXT NOT NULL,
`password` TEXT NOT NULL,
`created` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=4
;
CREATE TABLE `payment_table` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`productid` TEXT NOT NULL,
`userid` TEXT NOT NULL,
`created` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=4
;
SET GLOBAL event_scheduler = OFF;
SET GLOBAL event_scheduler = ON;
CREATE EVENT AutoDeleteOlProduct
ON SCHEDULE EVERY '1' HOUR
STARTS CURRENT_TIMESTAMP
ON COMPLETION PRESERVE
DO
DELETE FROM ShoppingMallDB.payment_table WHERE created < DATE_SUB(NOW(), INTERVAL 1 DAY);
INSERT INTO `user_table` (`id`, `name`, `password`, `created`)
VALUES
(0,'apm','123456',Now());
INSERT INTO `user_table` (`id`, `name`, `password`, `created`)
VALUES
(1,'abc','123456',Now());
INSERT INTO `user_table` (`id`, `name`, `password`, `created`)
VALUES
(2,'paas','123456',Now());
INSERT INTO `user_table` (`id`, `name`, `password`, `created`)
VALUES
(3,'user','123456',Now());
INSERT INTO `product_table` (`id`, `name`, `price`, `created`)
VALUES
(34211223411,'product1',2599,Now());
INSERT INTO `product_table` (`id`, `name`, `price`, `created`)
VALUES
(34211223412,'product2',3488,Now());
INSERT INTO `product_table` (`id`, `name`, `price`, `created`)
VALUES
(34211223413,'product3',2299,Now());
INSERT INTO `product_table` (`id`, `name`, `price`, `created`)
VALUES
(34211223414,'product4',1345,Now());
当然出于安全考虑,程序也可以不连接数据库的root用户,可以使用其他用户操作,这里新建一个用户:
use mysql;
select host, user from user;
create user apm identified by 'paasapm';
grant all on ShoppingMallDB.* to apm@'%' identified by 'paasapm' with grant option;
flush privileges;
use information_schema;
show variables like 'validate_password%;
set global validate_password_length=6;
set global validate_password_policy=0;