简体   繁体   English

PHP / MYSQL在数据库中存储大型数据集

[英]PHP/MYSQL Store large data sets on a database

I am building a platform collecting and parsing "csv" files which contains 5000 rows average and 40 columns; 我正在构建一个收集和解析“csv”文件的平台,其中包含5000行平均值和40列; files can be uploaded by any registered user so there should be no theoretically limit on how many files can be uploaded and stored (assuming I'm not having more than 20 uploads per day however). 任何注册用户都可以上传文件,因此理论上不应该限制上传和存储的文件数量(假设我每天上传的内容不超过20个)。 These file are being parsed by a custom made PHP parser which is kinda efficient but here comes the problem: storage. 这些文件由定制的PHP解析器解析,这种解析器有点高效,但问题出在这里:存储。 In particular, I would like to store these data in a MySQL db for later use: how should I organize my database? 特别是,我想将这些数据存储在MySQL数据库中供以后使用:我应该如何组织我的数据库? Should I create a table containing a row per file with each cell containing the content of each column of the original file? 我应该创建一个包含每个文件行的表,每个单元格包含原始文件的每列的内容吗? Or should I insert a single row for every row in the file? 或者我应该为文件中的每一行插入一行? The first one seems to me kinda better because of the huge number of rows built up by the second solution but also less efficient because any time I have to extract any data in the database, I will have to parse again the whole blob then extract the data I need 第一个似乎更好,因为第二个解决方案构建了大量的行,但效率也较低,因为任何时候我必须在数据库中提取任何数据,我将不得不再次解析整个blob然后提取我需要的数据

Given the fact that i can't store the data in PHP arrays due to lack of memory if too many users connect at the same time, which would be the best solution in this case? 鉴于如果有太多用户同时连接,由于内存不足,我无法将数据存储在PHP数组中,这在这种情况下是最佳解决方案吗?

Since all the files have the same columns, you should store them in one table and add another an additional column (possibly referencing a second table with one row per upload) to uniquely identify a set of rows. 由于所有文件都具有相同的列,因此应将它们存储在一个表中,并添加另一个列(可能引用第二个表,每个上载一行)以唯一标识一组行。

Eg: 例如:

rowId, setId, col1, col2, ...
1, 1, 'abc', 'def', ...
2, 1, 'abc', 'def', ...
3, 1, 'abc', 'def', ...
4, 2, 'abc', 'def', ...
5, 2, 'abc', 'def', ...
6, 2, 'abc', 'def', ...

This is what the data might look like for 2 sets of 3 rows each. 这就是每组2行3组数据的样子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM