# 建表語句 CREATE TABLE IF NOT EXISTS `price_history` ( `regionID` INT NOT NULL, `typeID` INT NOT NULL, `date` DATE NOT NULL, `lowPrice` DOUBLE NOT NULL, `highPrice` DOUBLE NOT NULL, `avgPrice` DOUBLE NOT NULL, `volume` INT NOT NULL, `orders` INT NOT NULL COMMENT 'regionID,typeID,date,lowPrice,highPrice,avgPrice,volume,orders', INDEX `regionID`(`regionID`), INDEX `typeID`(`typeID`), INDEX `date`(`date`), INDEX `lowPrice`(`lowPrice`), INDEX `highPrice`(`highPrice`), INDEX `avgPrice`(`avgPrice`), INDEX `volume`(`volume`), INDEX `orders`(`orders`) ) ENGINE = InnoDB DEFAULT CHARSET = UTF8MB4;
考慮到price字段使用FLOAT/DOUBLE類型會有精度問題(FLOAT 4個字節,有效數字6位;DOUBLE 8個字節,有效數字16位。)php
# 優化之後的建表語句,關於DECIMAL請參見 https://dev.mysql.com/doc/refman/5.7/en/precision-math-decimal-characteristics.html CREATE TABLE IF NOT EXISTS `price_history` ( `regionID` INT NOT NULL, `typeID` INT NOT NULL, `date` DATE NOT NULL, `lowPrice` DECIMAL(17, 4) NOT NULL, `highPrice` DECIMAL(17, 4) NOT NULL, `avgPrice` DECIMAL(17, 4) NOT NULL COMMENT 'The max(highPrice) is 700,000,000,000', `volume` INT NOT NULL, `orders` INT NOT NULL COMMENT 'regionID,typeID,date,lowPrice,highPrice,avgPrice,volume,orders', INDEX `regionID`(`regionID`), INDEX `typeID`(`typeID`), INDEX `date`(`date`), INDEX `lowPrice`(`lowPrice`), INDEX `highPrice`(`highPrice`), INDEX `avgPrice`(`avgPrice`), INDEX `volume`(`volume`), INDEX `orders`(`orders`) ) ENGINE = InnoDB DEFAULT CHARSET = UTF8MB4;
接下來進行數據的導入,表空間佔用累計爲70223M。html
# 數據導入 LOAD DATA LOCAL INFILE '/root/priceHistory.txt' INTO TABLE price_history FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'; MySQL [eveonline_price]> LOAD DATA LOCAL INFILE '/root/priceHistory.txt' INTO TABLE price_history FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'; Query OK, 269257439 rows affected, 14686 warnings (5 hours 25 min 41.31 sec) Records: 269257439 Deleted: 0 Skipped: 0 Warnings: 14686
首先,從網上下載比較新的typeID文件,而後進行適當的處理:首先去掉第一和第二行,而後將空格分割的文件進行處理,以逗號進行分割。mysql
# 下載下來的文件保存爲download.txt,處理後文件保存爲typeID.txt with open('typeID.txt', mode='w', encoding="UTF-8") as out: for line in open('download.txt', mode='r', encoding="UTF-8"): line = re.sub(r'\s+', ' ', line).split() key= line[0] name = ' '.join(line[1:]) out.write(key + ',' + name + "\n")
創建typeid表web
# MySQL數據庫字段支持大小寫,可是底層一概轉換成小寫(typeID和typeid是同一字段) CREATE TABLE IF NOT EXISTS `typeid` ( `typeID` MEDIUMINT PRIMARY KEY, `typeName` VARCHAR(90) NOT NULL, INDEX `typeName`(`typeName`) ) ENGINE = InnoDB DEFAULT CHARACTER SET = UTF8MB4;
通過對文件的讀取判斷,typeName字段最長爲78個字符,這裏留90字符做爲保留量。接下來進行數據的導入,sql
LOAD DATA LOCAL INFILE '/root/typeID.txt' INTO TABLE typeid FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
Importing market data into Excel,如何將市場數據導入Excelthinkphp
USING ESI WITH GOOGLE SHEETS,將ESI和Google Sheets配合使用數據庫
Marketplace,CCP官方論壇交易市場優化
EVE Online Intelligence Data,Tools and data you need to succeed in EVE Onlinegoogle
EVE Trade,暫時不知道作什麼用spa
EVE Online price history download link,大小
Development Blog,開發者日誌
MySQL部分知識: