Home > database >  strange mysql select loop with ; but not \G
strange mysql select loop with ; but not \G

Time:11-05

We have a server with old php (5.2.9) and mysql (5.0.67). It's a site that's been working for years. Now it stuck.

With strace I saw it gets stuck on a select query

running the command from mysql

select * from table \G

works fine

select * from table;

does not stop running and running and running until I Ctrl C it.

I know it's an ancient server and config but that's still strange, no?

CodePudding user response:

When you use ; to terminate the query, the results are formatted in a table. It has to read all the results before it prints anything, because it has to find the maximum width of each column so they'll all be aligned. If the query returns lots of data it will hang for a while before it starts printing anything.

\G makes it print each row vertically, with the columns on separate lines. This allows it to start printing as soon as the database starts returning results.

  • Related