Limit length of longtext field in SELECT results
The best way to clean up the readability of the results from a query in your terminal window is to use the mysql pager, not modifying your query as that can be too cumbersome.
Set the pager:
mysql> pager less -S
Do your query:
mysql> SELECT * FROM ...
This will put your results in a more readable format. You can use your arrow keys to page up and down and left and right to see the full table. Just press Q
to get out of pager mode for that query, and then just run
mysql> pager more
to return to the normal output river if you want.
You can use the LEFT()
function to get only the first characters:
SELECT LEFT(LongField, 20) AS LongField_First20chars
FROM ...
Use MySQL's SUBSTRING
function, as described in the documentation. Like:
SELECT SUBSTRING(`text`, 1, 100) FROM blog_entry;
To select first 100 chars.