主頁(yè) > 知識(shí)庫(kù) > MySQL如何利用存儲(chǔ)過(guò)程快速生成100萬(wàn)條數(shù)據(jù)詳解

MySQL如何利用存儲(chǔ)過(guò)程快速生成100萬(wàn)條數(shù)據(jù)詳解

熱門標(biāo)簽:話務(wù)外呼系統(tǒng)怎么樣 400電話可以辦理嗎 智能外呼系統(tǒng)復(fù)位 拉卡拉外呼系統(tǒng) 大眾點(diǎn)評(píng)星級(jí)酒店地圖標(biāo)注 外東北地圖標(biāo)注 高清地圖標(biāo)注道路 云南電商智能外呼系統(tǒng)價(jià)格 臨清電話機(jī)器人

前言

在測(cè)試的時(shí)候?yàn)榱藴y(cè)試大數(shù)據(jù)量的情況下項(xiàng)目的抗壓能力我們通常要?jiǎng)?chuàng)造一些測(cè)試數(shù)據(jù)那么現(xiàn)在這個(gè)方法絕對(duì)好用

其中可能會(huì)有sql空間的報(bào)錯(cuò)可以自己嘗試解決,這里做了分批插入,每次插入30萬(wàn)條,所以沒(méi)有遇到類似的空間問(wèn)題

首先,創(chuàng)建要插入100萬(wàn)數(shù)據(jù)的表格

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
 
-- ----------------------------
-- Table structure for sdb_b2c_orders
-- ----------------------------
DROP TABLE IF EXISTS `sdb_b2c_orders`;
CREATE TABLE `sdb_b2c_orders`  (
  `order_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '訂單號(hào)',
  `seller_order_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '商戶訂單號(hào)',
  `total_amount` decimal(20, 3) NOT NULL DEFAULT 0.000 COMMENT '商品默認(rèn)貨幣總值',
  `final_amount` decimal(20, 3) NOT NULL DEFAULT 0.000 COMMENT '訂單貨幣總值, 包含支付價(jià)格,稅等',
  `pay_status` enum('0','1','2','3','4','5') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '付款狀態(tài) 0-未支付 1-已支付 2-已付款至擔(dān)保方 3-部分付款 4-部分退款 5-全額退款',
  `ship_status` enum('0','1','2','3','4') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '發(fā)貨狀態(tài)',
  `is_delivery` enum('Y','N') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'Y' COMMENT '是否需要發(fā)貨',
  `createtime` int(10) UNSIGNED NULL DEFAULT NULL COMMENT '下單時(shí)間',
  `last_modified` int(10) UNSIGNED NULL DEFAULT NULL COMMENT '最后更新時(shí)間',
  `ectools_payments` varchar(512) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `payment` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '支付方式',
  `shipping_id` mediumint(8) UNSIGNED NULL DEFAULT NULL COMMENT '配送方式',
  `shipping` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '配送方式',
  `member_id` mediumint(8) UNSIGNED NULL DEFAULT NULL COMMENT '會(huì)員用戶名',
  `platform_member_id` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '平臺(tái)會(huì)員ID',
  `store_id` mediumint(8) UNSIGNED NULL DEFAULT NULL COMMENT '收款門店ID',
  `confirm_status` enum('0','1','2','3') CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '0' COMMENT '門店接單狀態(tài)',
  `confirm_time` int(10) UNSIGNED NULL DEFAULT NULL COMMENT '接單時(shí)間',
  `pickself_status` enum('0','1') CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '自提狀態(tài)',
  `pickself_time` int(10) NULL DEFAULT NULL COMMENT '自提時(shí)間',
  `pickself_id` mediumint(8) UNSIGNED NULL DEFAULT NULL COMMENT '自提門店ID',
  `operator_id` mediumint(8) UNSIGNED NULL DEFAULT NULL COMMENT '收款用戶ID',
  `weixinscan_qrcode` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '微信付款碼',
  `alipay_qrcode` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '支付寶付款碼',
  `unionpay_qrcode` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '銀聯(lián)付款碼',
  `qrcode` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '核銷碼',
  `promotion_type` enum('normal','prepare','recharge','cashier') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'normal' COMMENT '銷售類型',
  `status` enum('active','dead','finish') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'active' COMMENT '訂單狀態(tài)',
  `confirm` enum('Y','N') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'N' COMMENT '確認(rèn)狀態(tài)',
  `ship_area` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '收貨地區(qū)',
  `ship_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '收貨人',
  `weight` decimal(20, 3) NULL DEFAULT NULL COMMENT '訂單總重量',
  `tostr` longtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '訂單文字描述',
  `itemnum` mediumint(8) UNSIGNED NULL DEFAULT NULL COMMENT '訂單子訂單數(shù)量',
  `ip` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT 'IP地址',
  `ship_addr` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '收貨地址',
  `ship_zip` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '收貨人郵編',
  `ship_tel` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '收貨電話',
  `ship_email` varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '收貨人email',
  `ship_time` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '配送時(shí)間',
  `ship_mobile` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '收貨人手機(jī)',
  `cost_item` decimal(20, 3) NOT NULL DEFAULT 0.000 COMMENT '訂單商品總價(jià)格',
  `is_tax` enum('true','false') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'false' COMMENT '是否要開(kāi)發(fā)票',
  `tax_type` enum('false','personal','company') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'false' COMMENT '發(fā)票類型',
  `tax_content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '發(fā)票內(nèi)容',
  `cost_tax` decimal(20, 3) NOT NULL DEFAULT 0.000 COMMENT '訂單稅率',
  `tax_company` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '發(fā)票抬頭',
  `is_protect` enum('true','false') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'false' COMMENT '是否還有保價(jià)費(fèi)',
  `cost_protect` decimal(20, 3) NOT NULL DEFAULT 0.000 COMMENT '保價(jià)費(fèi)',
  `cost_payment` decimal(20, 3) NULL DEFAULT NULL COMMENT '支付費(fèi)用',
  `currency` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '訂單支付貨幣',
  `cur_rate` decimal(10, 4) NULL DEFAULT 1.0000 COMMENT '訂單支付貨幣匯率',
  `score_u` decimal(20, 3) NOT NULL DEFAULT 0.000 COMMENT '訂單使用積分',
  `score_g` decimal(20, 3) NOT NULL DEFAULT 0.000 COMMENT '訂單獲得積分',
  `discount` decimal(20, 3) NOT NULL DEFAULT 0.000 COMMENT '訂單減免',
  `pmt_goods` decimal(20, 3) NULL DEFAULT NULL COMMENT '商品促銷優(yōu)惠',
  `pmt_order` decimal(20, 3) NULL DEFAULT NULL COMMENT '訂單促銷優(yōu)惠',
  `payed` decimal(20, 3) NULL DEFAULT 0.000 COMMENT '訂單支付金額',
  `memo` longtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '訂單附言',
  `disabled` enum('true','false') CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT 'false',
  `displayonsite` enum('true','false') CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT 'true',
  `mark_type` varchar(2) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'b1' COMMENT '訂單備注圖標(biāo)',
  `mark_text` longtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '訂單備注',
  `cost_freight` decimal(20, 3) NOT NULL DEFAULT 0.000 COMMENT '配送費(fèi)用',
  `extend` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT 'false' COMMENT '訂單擴(kuò)展',
  `order_refer` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'local' COMMENT '訂單來(lái)源',
  `addon` longtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '訂單附屬信息(序列化)',
  `source` enum('pc','wap','weixin','cashier','paycode','eleme','meituan') CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT 'pc' COMMENT '平臺(tái)來(lái)源',
  `source_name` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '商圈庫(kù)名',
  `merchant_bn` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '商戶號(hào)',
  UNIQUE INDEX `idx_bn`(`order_id`, `merchant_bn`) USING BTREE,
  INDEX `ind_ship_status`(`ship_status`) USING BTREE,
  INDEX `ind_pay_status`(`pay_status`) USING BTREE,
  INDEX `ind_promotion_type`(`promotion_type`) USING BTREE,
  INDEX `ind_status`(`status`) USING BTREE,
  INDEX `ind_disabled`(`disabled`) USING BTREE,
  INDEX `ind_last_modified`(`last_modified`) USING BTREE,
  INDEX `ind_createtime`(`createtime`) USING BTREE,
  INDEX `idx_order_refer`(`order_refer`) USING BTREE,
  INDEX `idx_bn_aa`(`merchant_bn`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '訂單表' ROW_FORMAT = Dynamic;
 
SET FOREIGN_KEY_CHECKS = 1;

創(chuàng)建函數(shù)

隨機(jī)產(chǎn)生字符串

DELIMITER $$
CREATE FUNCTION rand_string(n INT) RETURNS VARCHAR(255)
BEGIN
 DECLARE chars_str VARCHAR(100) DEFAULT 'abcdefghijklmnopqrstuvwxyzABCDEFJHIJKLMNOPQRSTUVWXYZ';
 DECLARE return_str VARCHAR(255) DEFAULT '';
 DECLARE i INT DEFAULT 0;
 WHILE i  n DO
 SET return_str =CONCAT(return_str,SUBSTRING(chars_str,FLOOR(1+RAND()*52),1));
 SET i = i + 1;
 END WHILE;
 RETURN return_str;
END $$

隨機(jī)產(chǎn)生數(shù)字

DELIMITER $$
CREATE FUNCTION rand_num( ) 
RETURNS INT(5)  
BEGIN   
 DECLARE i INT DEFAULT 0;  
 SET i = FLOOR(100+RAND()*10);  
RETURN i;  
 END $$
 
 
#假如要?jiǎng)h除
#drop function rand_num;

創(chuàng)建存儲(chǔ)過(guò)程

并向表中插入數(shù)據(jù)

#執(zhí)行存儲(chǔ)過(guò)程,往sdb_b2c_order表添加隨機(jī)數(shù)據(jù)
DELIMITER $$
CREATE PROCEDURE insert_sdb_b2c_orders(IN START INT(10),IN max_num INT(10))  
BEGIN  
DECLARE i INT DEFAULT 0;   
 SET autocommit = 0;    
 REPEAT  
 SET i = i + 1;  
 INSERT INTO sdb_b2c_orders (order_id ,seller_order_id,total_amount,final_amount,source,source_name,merchant_bn ) VALUES
 (rand_string(10) ,rand_string(10),100,100,'eleme','square',(START+i));  
 UNTIL i = max_num  
 END REPEAT;  
 COMMIT;  
 END $$;
 
 
#刪除
# DELIMITER ;
# drop PROCEDURE insert_emp;

調(diào)用存儲(chǔ)過(guò)程進(jìn)行插入數(shù)據(jù)

 #插入30萬(wàn)條數(shù)據(jù)分幾次插入
 CALL insert_sdb_b2c_orders(700003,300000); 

結(jié)果

 

總結(jié)

百萬(wàn)數(shù)據(jù)搞定,到此這篇關(guān)于MySQL如何利用存儲(chǔ)過(guò)程快速生成100萬(wàn)條數(shù)據(jù)的文章就介紹到這了,更多相關(guān)MySQL用存儲(chǔ)過(guò)程生成100萬(wàn)數(shù)據(jù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • MySQL 到底是如何做到多版本并發(fā)的?
  • mysql過(guò)濾復(fù)制思路詳解
  • MySQL 外鍵(FOREIGN KEY)用法案例詳解
  • Python接口自動(dòng)化淺析pymysql數(shù)據(jù)庫(kù)操作流程
  • MySQL事務(wù)控制流與ACID特性
  • Mysql使用存儲(chǔ)過(guò)程快速添加百萬(wàn)數(shù)據(jù)的示例代碼
  • MySQL去除重疊時(shí)間求時(shí)間差和的實(shí)現(xiàn)
  • Mysql數(shù)據(jù)庫(kù)中datetime、bigint、timestamp來(lái)表示時(shí)間選擇,誰(shuí)來(lái)存儲(chǔ)時(shí)間效率最高
  • MySQL的全局鎖和表級(jí)鎖的具體使用
  • 基于Redo Log和Undo Log的MySQL崩潰恢復(fù)解析

標(biāo)簽:揚(yáng)州 溫州 福州 無(wú)錫 定西 阿里 三明 山西

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《MySQL如何利用存儲(chǔ)過(guò)程快速生成100萬(wàn)條數(shù)據(jù)詳解》,本文關(guān)鍵詞  MySQL,如何,利用,存儲(chǔ),過(guò)程,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《MySQL如何利用存儲(chǔ)過(guò)程快速生成100萬(wàn)條數(shù)據(jù)詳解》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于MySQL如何利用存儲(chǔ)過(guò)程快速生成100萬(wàn)條數(shù)據(jù)詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章