Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

strange mysql select loop with ; but not \G

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading