问题
I have a table which consists of around 2500 rows for a single user id. And for each user id, same number of rows will be there. If number of users increase then I am afraid number of rows will be vast.
So can you please suggest me what to do ? Should I use different tables for different users or a single table for all users. And another thing , is there any limitation of how many maximum number rows/columns can be there in a single table ?
My database looks like below structure :
for User1
id ---- col1
1 ---- value1
2 ---- value2
..............
2500 ---- value 2500
for User2
id ---- col1 ...
1 ---- value1
2 ---- value2
..............
2500 ---- value 2500
likewise it will continue for suppose 1 million users
So, should I go for creating separate tables for each users or should I create 1 table containing all the records.
回答1:
Use a table as you are. MySQL can easily handle billions or rows of data. With some nice indexes your performance should be quite good as well.
That's not to say that you shouldn't be looking to ensure that you have good table design, but you also shouldn't be worried about handling what you think is probably loads of data - when in actual fact it is likely a drop in the ocean of datasets.
The number of columns really doesn't make TOO much difference, the row size can increase the time it takes a hard drive to access them (according to a few articles I have read) but at the same time, you would have to have a REALLY big row to actually notice the difference across thousands of queries.
As for good structure, it really depends on HOW you will need to use it. If you will be performing many different aggregate functions, ensure you have a table that will allow for it. If you need only a few specific queries, it might be good to create a report specific table that aggregates the data say once per day.
Edit: Notes on actual limit to number of rows:
http://dev.mysql.com/doc/refman/5.1/en/source-configuration-options.html
The MyISAM storage engine supports 2^32 rows per table, but you can build MySQL with the --with-big-tables option to make it support up to 2^64 rows per table.
http://dev.mysql.com/doc/refman/5.1/en/innodb-restrictions.html
The InnoDB storage engine doesn't seem to have a limit on the number of rows, but it has a limit on table size of 64 terrabytes. How many rows fits into this depends on the size of each row.
来源:https://stackoverflow.com/questions/22908895/how-to-store-large-number-of-records-in-mysql-database