📜 ⬆️ ⬇️

Tuning the console client MySQL

I quite often, even constantly have to access different MySQL databases. Having tried many different GUI clients, I realized that they did not satisfy me. That problems with the coding, there is no auto-completion code, the query history does not work. So I came to use the mysql console client. And everything seems to be fine, but there were a couple of problems.
First of all, going into the next bookmark with an open mysql connection, I stupidly looked at the invitation line and tried to understand what server I am on and which database is connected to. Secondly, when displaying a large number of fields or when displaying a field with a length exceeding the width of the terminal, porridge was made of dashes, letters and sticks :). The other day I rummaged through the documentation and figured out something.
So invitation. You can interactively switch using the command prompt. For example:

mysql>
mysql> prompt (\u@\h) [\d]>
PROMPT set to '(\u@\h) [\d]>'
(www@192.168.1.33) [poll]>


where \ u is a user, \ h is a host and \ d is a database
')
Now about the output. The variable pager determines through which program the output of the query results will be presented. After some experiments with more and less, I came up with the following option:

(www@192.168.1.33) [poll]>pager less -n -i -S
PAGER set to 'less -n -i -S'


As a result, the request will be seen in the familiar interface less with all the goodies of the search type, etc .:
image

Of course, you can enter these commands interactively, you can write them as system variables, but it is still more convenient to write them once in the ~ / .my.cnf file like so:

[client]
default-character-set= utf8
pager = less -n -i -S
prompt =(\u@\h) [\d]>


I hope you enjoy this tuning and you will adopt my advice.

UPD. Since the article was written for use in linux systems, and the issues raised in it are of interest to Windows users, I consider it necessary to add that:
1. In Windows, reading the default MySQL parameters is done from the following file:
C: \ my.cnf
2. less for Windows can be installed separately. Link - http://gnuwin32.sourceforge.net/packages/less.htm

Source: https://habr.com/ru/post/82402/


All Articles