Mysql – SELECT Query is slow when run remotely in MySQL

MySQLperformancequery-performance

When I connect MySQL from remote server and run below query then the results are very slow(Sometime even faced lost connection Issue). However when I run the same SQL query on the local machine then It's results are very fast.

    SELECT * FROM CUSTOMERS

The customer tale contains two million records.

I have also enable skip-host-cache and skip-name-resolve in MySQL configuration.

Both machine is connected using the LAN IP and customer table is InnoDB table. I am using MySQL 5.6.

Can you please suggest me on this, why SQL query are very slow when run It from remote machine.

Thank you,
Sujeet

Best Answer

LIMIT will work for the first 5000, but will get slower and slower as you move on (with OFFSET) to subsequent chunks. So that's not a good way to process a large table in chunks.

Does the table have a PRIMARY KEY? (If not, why not?) Use that for very efficient chunking. It will avoid the timeouts you are getting.

A discussion of chunking. (That is aimed at DELETE, but it can easily be adapted to SELECT.) The trick is to "remember where you left off".