mysql客户端中的命令历史记录仅显示多行查询的最后一行 [英] Command history in mysql client only showing last line of multiline query

查看:101
本文介绍了mysql客户端中的命令历史记录仅显示多行查询的最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在OSX的Terminal.app中的Bash中使用Mysql的命令行客户端在Screen/Tmux中. 当使用向上箭头重新显示跨越行而不是在线的先前运行的查询时,并且当光标位于终端的最后一行时,mysql的命令历史记录中的命令将被截断"或切断.当我在Ubuntu工作站上使用相同的工具时,这永远不会发生

I'm using Mysql's command-line client in Screen/Tmux, from Bash in OSX's Terminal.app. When using arrow-up to re-display a previously run query that spanned more than on line, AND when the cursor is on the very last line of the Terminal, the command in mysql's command history gets 'truncated', or cut off. This never happens when I use the same tools on my Ubuntu workstation

以下是发生的情况的直观表示:

Here's a visual representation of what happens:

键入一些查询;这里没什么问题.

Typing some query; nothing wrong here.

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

运行它,结果显示:

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

点击[向上箭头]以重新显示上一个查询时,我会遇到以下问题:

Hitting [arrow-up] to re-display last query leaves me with:

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

再按一次[箭头键],我得到:

Hit [arrow-up] again, I get:

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

可以通过更改设置来解决吗?还是在Mysql的客户端中有bug?

Could the be solved by changing a setting? Or is it a bug in Mysql's client?

软件版本:

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

推荐答案

在这方面,您可以通过几种选择使您的生活更轻松:

You have a few options I can think of to make your life easier in this regard:

  • readline命令结合mysql选项: readline接受类似于基本emacs命令的命令(也可以设置为vi) ,或示例CTRL-a使您返回到行的开头.

  • readline commands combined with mysql options: readline accepts commands similar to basic emacs commands (can be set to vi as well), or example CTRL-a returns you to the start of a line.

set horizontal-scroll-mode On(阅读行)结合使用您在~/.inputrc中进行设置,可以使您以1条直线获得输入,将光标放在最底端.结合使用CTRL-a可以立即跳到开头,非常方便.

this combined with set horizontal-scroll-mode On, a readline that you set in ~/.inputrc, which allows you to get your input in 1 straight line, putting your cursor at the very end. Combine it with CTRL-a to immediately jump to the beginning and it's quite 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

(某些系统上肯定是OSX 10.5,我相信使用libedit代替readline,在这种情况下,如果不确定系统是否发出mysql --version命令,则需要将其全部放在~/.editrc中)

(some systems, OSX 10.5 for certain I believe use libedit instead of readline, in which case you need to put it all in ~/.editrc, if you're not sure about your system issue the mysql --version command )

要查找发出的命令,您还具有CTRL-r,它允许您键入一个术语,并且将在历史记录中搜索最后一次出现的情况.

To look for commands you issued you also have CTRL-r, which allows you to type in a term and your history will be searched for the last occurence.

有趣的命令是:

  • CTRL-P转到历史记录中的上一个命令
  • CTRL-N转到历史记录中的下一步"命令
  • CTRL-R反向搜索历史记录
  • CTRL-S向前搜索您的历史记录
  • CTRL-A将光标移至行首
  • CTRL-E将光标移至行的末尾
  • CTRL-W向后删除单词
  • ALT-D向前删除一个单词
  • CTRL-F向前移动光标1个字符
  • CTRL-B向后移动光标1个字符
  • ALT-F将光标向前移动1个单词
  • ALT-B向后移动光标1个字
  • ALT-_撤消


  • CTRL-P go to the Previous command in your history
  • CTRL-N go to the Next command in your history
  • CTRL-R Reverse-search through your history
  • CTRL-S Search forward through your history
  • CTRL-A Move the cursor to the beginning of the line
  • CTRL-E Move the cursor to the end of the line
  • CTRL-W delete a Word backwards
  • ALT-D delete a word forwards
  • CTRL-F move the cursor Forward 1 character
  • CTRL-B move the cursor Backward 1 character
  • ALT-F move the cursor Forward 1 word
  • ALT-B move the cursor Backward 1 word
  • ALT-_ undo


取决于您的shell和底层,它们可能无法全部运行或被拦截.例如,在我在kde上使用的Konsole上,我不得不在高级设置中禁用流控制,以允许使用CTRL-s等.

Depending on your shell and the underlying they might not all work or be intercepted though. For example on Konsole, which I use on kde, I had to disable flow-control in advanced settings to allow for CTRL-s amongst others.

最后,mysql还为您提供 \ e命令允许您在常规文件编辑器中编辑命令,如果不是vi或emacs的话,请尝试使用nano,这很简单并且效果很好.使用此方法的主要缺点是,在向上滚动换行符时,会忽略bu制表符,而不会空格.这只是一个unix的事情,但是OS X应该可以在那做得很好,因为我不拥有任何Apple电脑,所以无法检查,对不起. :)

Finally mysql also gives you 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's easy and works well. The main disadvantage of using this is that when scrolling up newlines are ignored bu tabs and spaces aren't. It's a unix only thing but OS X should do fine there, can't check since I don't own any Apple computers, sorry. :)

要更轻松地使用此命令,您可以在~/.inputrc中放置一个readline字符串宏. 例如Control-o: "\\e;\n"将CONTROL-o绑定到\ e;然后按 enter 即可立即执行. (请查看键绑定部分)

To more easily use this command you could put a readline string macro in ~/.inputrc e.g. Control-o: "\\e;\n" would bind CONTROL-o to \e; followed by enter for instant execution. (look at the Keybindings Section)

使用备用外壳: 例如 altSQL :它提供了语法着色,漂亮的历史记录滚动以及其他一些优点,很大的好处是您有资源,以便您可以调整所需的内容.

use an alternate shell: such as altSQL: it gives syntax colouring, nice history scrolling and some other niceties, big bonus is that you have the source so you can adapt what you want.

放下外壳并进入GUI : 最后,我想插入漂亮的 MySQL工作台以在您的数据库上工作,这是跨平台的,平台,是免费的,我认为这是一个很好的工具.

drop the shell and go GUI: Finally I'd like to plug the nice MySQL workbench to work on your databases, it's cross-platform, free and in my humble opinion a nice tool to work with.

我意识到这不是一个完美的解决方案,并且各有优缺点,但我希望这对您有所帮助.

I realise it's not a perfect solution and each have advantages and drawbacks but I hope this has helped you along somewhat.

这篇关于mysql客户端中的命令历史记录仅显示多行查询的最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆