How to adjust display settings of mysql command line?
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 these settings so tha开发者_如何学Ct it properly display results.
You can use the \G
command (instead of the ;
) at the end of your SQL queries...
Example:
SELECT * FROM USER \G
It will display your table in row form instead of column form.
mostly this happens when the row it fetches is too long. try playing with your terminal to have scroll bar and you could even reduce fonts.
The mysql option is
mysql> pager less -n -i -S
To set the scrolling automatically add this to your my.cnf file in the [client] section like this:
[client]
pager = less -n -i -S
In Microsoft Windows mysql Command Prompt, Right-click on the prompt boarder and select Properties, now select the Layout tab and change the Window Size width or screen buffer width to a more suitable view. That should fix the problem.
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.
精彩评论