Command Line of mysql is not displaying results properly. I mean some columns of table are in 1st line some in 2nd line. Output is also broken into two rows. How do I adjust the
Another option, which I was looking for and finally found, is the MySQL string function LEFT().
LEFT(
str
,
len
)
Returns the leftmost len characters from the string str, or NULL if any argument is NULL.
For example ...
mysql> SELECT
-> `bib`,
-> `name_id` AS `Print`,
-> `code`,
-> `name_en` AS `EN`,
-> `name_fr` AS `FR`,
-> `name_de` AS `DE`,
-> `Id`
-> FROM `iso639_Language`
-> WHERE `Id` LIKE 'in%'
-> ORDER BY `bib`;
+-----+------------------------------------------------------------+------+------------------------------------------------------------+------------------------------------------------+------------------+-----+
| bib | Print | code | EN | FR | DE | Id |
+-----+------------------------------------------------------------+------+------------------------------------------------------------+------------------------------------------------+------------------+-----+
| ina | Interlingua (International Auxiliary Language Association) | ia | Interlingua (International Auxiliary Language Association) | interlingua (langue auxiliaire internationale) | Interlingua | ina |
| ind | Indonesian | id | Indonesian | indonésien | Bahasa Indonesia | ind |
| inh | Ingush | NULL | Ingush | ingouche | Inguschisch | inh |
+-----+------------------------------------------------------------+------+------------------------------------------------------------+------------------------------------------------+------------------+-----+
3 rows in set (0.01 sec)
... becomes ...
mysql> SELECT
-> `bib`,
-> LEFT(`name_id`,15) AS `Print`,
-> `code`,
-> LEFT(`name_en`,10) AS `EN`,
-> LEFT(`name_fr`,10) AS `FR`,
-> LEFT(`name_de`,10) AS `DE`,
-> `Id`
-> FROM `iso639_Language`
-> WHERE `Id` LIKE 'in%'
-> ORDER BY `bib`;
+-----+-----------------+------+------------+-------------+------------+-----+
| bib | Print | code | EN | FR | DE | Id |
+-----+-----------------+------+------------+-------------+------------+-----+
| ina | Interlingua (In | ia | Interlingu | interlingu | Interlingu | ina |
| ind | Indonesian | id | Indonesian | indonésien | Bahasa Ind | ind |
| inh | Ingush | NULL | Ingush | ingouche | Inguschisc | inh |
+-----+-----------------+------+------------+-------------+------------+-----+
3 rows in set (0.00 sec)
I do like the \G
and pager less -Sin
options, and use them. Often, however, I need the results in a normal fashion. With the pager option I loose the ability to reference, visually, the previous results, as the output is displayed by the selected program, externally to MySQL, and is no longer displayed when that program is closed. With the \G
option I can easily compare the data of each record as a whole, but comparing records, such as viewing the column looking for patterns, or discrepancies, is not so easy.
What I used to do was remove some of the columns until the results fit in the window, and rerun the queries with other columns removed, and developed a "view" of the table in my mind. (Not a good place to keep tables.) I seldom need to view the entire column, however, when using MySQL in the terminal, and selectively reducing an excessively long column from a query can be done by editing the last command to insert LEFT()
around the offending column, and I'm back to doing what I needed to do, with little distraction or lost time.