Retrieving only a fixed number of rows in MySQL

 SELECT * FROM `your_table` LIMIT 0, 5000 

This will display the first 5000 results from the database.

 SELECT * FROM `your_table` LIMIT 1001, 5000 

This will show records from 1001 to 6000 (counting from 0).


MySQL is smart in that if you specify a LIMIT 5000 in your query, and it is possible to produce that result without generating the whole result set first, then it will not build the whole result.

For instance, the following query:

SELECT * FROM table ORDER BY column LIMIT 5000

This query will need to scan the whole table unless there is an index on column, in which case it does the smart thing and uses the index to find the rows with the smallest column.