The history of commands in the mysql client shows only the last line of a multiline query

I use the Mysql command-line client in Screen / Tmux, from Bash to OSX Terminal.app. When using the up arrow to redisplay a previously programmed query, which is larger than the line, and when the cursor is in the last line of the terminal, the command in the mysql command history gets "clipped" or disconnected. This never happens when I use the same tools on my Ubuntu workstation.

Here is a visual representation of what is happening:

Enter some query; nothing wrong here.

+-------------------------------------------+ |mysql> | |mysql> | |mysql> | |mysql>select * from tables where legs = 4 a| |nd colour = 'green'; | +-------------------------------------------+ 

Run it, the results are displayed:

 +-------------------------------------------+ || 2 | ....... | ..... | | |+---+---------+-------+ | | x rows in set (0.00 sec) | | | |mysql> | +-------------------------------------------+ 

Pressing [up arrow] to redisplay the last query leaves me with:

 +-------------------------------------------+ || 2 | ....... | ..... | | |+---+---------+-------+ | | x rows in set (0.00 sec) | | | |nd colour = 'green'; | +-------------------------------------------+ 

Press [up arrow] again, I get:

 +-------------------------------------------+ || 2 | ....... | ..... | | |+---+---------+-------+ | | x rows in set (0.00 sec) | |mysql>select * from tables where legs = 4 a| |nd colour = 'green'; | +-------------------------------------------+ 

Could it be solved by changing the setting? Or is this an error in the Mysql client?

Software version:

 OSX 10.7.3 Terminal Version 2.2.2 (303) GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin11) mysql Ver 14.14 Distrib 5.5.19, for osx10.7 (i386) using readline 5.1 Screen version 4.00.03 (FAU) 23-Oct-06 tmux 1.6 
+6
source share
1 answer

You have several options that I can come up with to make your life easier in this regard:

  • readline commands combined with mysql options . readline accepts commands similar to the main emacs commands (can also be installed on vi), or the CTRL-a example returns you to the beginning of the line.

    combined with set horizontal-scroll-mode On , readline , which you set to ~/.inputrc , which allows you to enter your input in 1 straight line by placing the cursor at the very end. Combine it with CTRL-a to jump directly to the beginning, and this is pretty convenient.

    ~/.inputrc :

     $if Mysql set horizontal-scroll-mode On` # uncomment the commands below to use vi keybindings #set keymap vi #set editing-mode vi $endif 

    (some systems, OSX 10.5, for sure, I believe that libedit is used instead of libline, in which case you need to put all this in ~/.editrc if you are not sure that your system issues the mysql --version command)

    To search for the commands you issued, you also have CTRL-r , which allows you to enter a term, and your story will look for the latest event.

    interesting teams are:

    • CTRL-P go to previous command in history
    • CTRL-N go to next command in history
    • CTRL-R Reverse Search Your History
    • CTRL-S Search Forward Through History
    • CTRL-A Move cursor to beginning of line
    • CTRL-E Move cursor to end of line
    • CTRL-W removes Word back
    • ALT-D removes the word forward
    • CTRL-F moves the cursor forward 1 character
    • CTRL-B moves the cursor back 1 character
    • ALT-F move the cursor forward 1 word
    • ALT-B moves the cursor back 1 word
    • ALT-_ undo


    Depending on your shell and base code, they may not work or intercept. For example, on Konsole, which I use on kde, I had to turn off flow control in advanced settings in order to enable CTRLs among others.

    Finally, mysql also provides the \ e command, which allows you to edit your commands in your general file editor, if vi or emacs isn't your thing, try nano, it works easily and well. The main disadvantage of using this is that when scrolling through newlines, the bu tabs and spaces are ignored. This is the only thing, but OS X should do it there perfectly, I can’t check, because I don’t own Apple computers, sorry. :)

    To make this command easier to use, you can put the readline string macro in ~/.inputrc for example Control-o: "\\e;\n" will bind CONTROL-o to \ e; then enter for immediate execution. (see Keyword Section )

  • use an alternative shell : for example altSQL : it gives syntax coloring, a nice scroll history and some other subtleties, a big bonus is that you have a source so that you can adapt what you want.

  • remove the shell and go to the GUI : Finally, I would like to connect a good MySQL workbench to work with your databases, it is cross-platform, free and in my humble opinion a good tool to work with.

I understand that this is not an ideal solution, and each has its own advantages and disadvantages, but I hope this helps you a bit.

+9
source

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


All Articles