12 04 2008
MySQL tip: Output query results vertically
Have you ever pulled your hair out trying to read excessively long query results that wrap onto multiple lines in the mysql command-line program? This happens to me about once a week, so today I went hunting for a better way. Turns out it's super easy and incredibly useful!
Here's an example of what this might look like on your screen:
mysql> SELECT * FROM customers; +-------------+------------+---------------------+-------+---- --------+-----------+------------------------+-----------+---- ----------+-------+----------+-------------+---------------+-- ------------+ | customer_id | address_id | stamp | title | first_name | last_name | address | address_2 | city | state | province | postal_code | country | phone_number | +-------------+------------+---------------------+-------+---- --------+-----------+------------------------+-----------+---- ----------+-------+----------+-------------+---------------+-- ------------+ | 1 | 1 | 2008-12-04 12:00:00 | Mr. | Ben | Rothe | 8555 Cedar Place Drive | Suite 114 | Indianapolis | IN | | 46240 | United States | 317-251-6744 | +-------------+------------+---------------------+-------+---- --------+-----------+------------------------+-----------+---- ----------+-------+----------+-------------+---------------+-- ------------+ 1 row in set (0.00 sec)
To output this result set vertically, just end your query with \G instead of a ; character.
mysql> SELECT * FROM customers\G *************************** 1. row *************************** customer_id: 1 address_id: 1 stamp: 2008-11-24 15:41:25 title: Mr. first_name: Ben last_name: Rothe address: 8555 Cedar Place Drive address_2: Suite 114 city: Indianapolis state: IN province: postal_code: 46240 country: United States phone_number: 317-251-6744 1 row in set (0.00 sec)
How cool is that?!?