MariaDB 客户端在 Emacs sql-mode 中没有提示

cjm*_*cjm 7 emacs mysql mariadb

我刚刚在 Arch Linux 上从旧的 MySQL 客户端升级到mariadb-clients-10.0.21-3。升级后,在使用Emacs的sql-mysql功能时不再看到提示了。

似乎mysql正在缓冲提示,因为它显示在输出的第一行:

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 19662
Server version: 4.1.11-standard-log

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

show tables;
MySQL [dbname]> +---------------------------------------------------------+
| Tables_in_dbname                                           |
+---------------------------------------------------------+
...
+---------------------------------------------------------+
80 rows in set (0.02 sec)

help
MySQL [dbname]> 
General information about MariaDB can be found at
http://mariadb.org

List of all MySQL commands:
...
For server side help, type 'help contents'

?
MySQL [dbname]> 
General information about MariaDB can be found at
http://mariadb.org

List of all MySQL commands:
...
For server side help, type 'help contents'

exit
MySQL [dbname]> Bye
Run Code Online (Sandbox Code Playgroud)

在所有情况下,“ MySQL [dbname]>”之前的行都是我输入的。(...表示我省略了输出。)

如何让提示正确显示? 我已经尝试了以下-n选项mysql;它没有效果。如果我mysql在终端中运行,它工作正常。

小智 6

你忘记转义特殊字符了。Elisp-regex 的反斜杠很重,因为第一个 \ 被 lisp 字符串吞没了。见https://www.emacswiki.org/emacs/RegularExpression

为了捕获 MariaDB 和 MySQL,我的配置中有这个:

(sql-set-product-feature 'mysql :prompt-regexp "^\\(MariaDB\\|MySQL\\) \\[[_a-zA-Z]*\\]> ")

  • 它可以工作,但是当没有选择数据库时,提示是: MariaDB [(none)]> 更改正则表达式以匹配它: (sql-set-product-feature 'mysql :prompt-regexp "^\\(MariaDB\ \|MySQL\\) \\[[(_a-zA-Z)]*\\]> ") (2认同)
  • ^ 有用的一点,但请确保也包括双斜杠,因为答案建议:`(sql-set-product-feature 'mysql :prompt-regexp "^\\(MariaDB\\|MySQL\\) \\[[_a -zA-Z()]*\\]> ")` (2认同)

cjm*_*cjm 2

问题原来是提示与预期不符sql-mode。MariaDB 使用“MySQL [dbname]>”作为默认提示符,并且sql-mode只允许“mysql>”。

因此,一种修复方法是将“--prompt=mysql>”添加到sql-mysql-options

(setq sql-mysql-options '("--prompt=mysql> "))
Run Code Online (Sandbox Code Playgroud)

更好的方法是修复正则表达式以允许任一提示样式。但我在让它发挥作用时遇到了一些困难,所以如果有人发布如何做到这一点,我将奖励赏金。

我试过了

(sql-set-product-feature 'mysql :prompt-regexp "^[mM]y[sS][qQ][lL][^>]*> ")
Run Code Online (Sandbox Code Playgroud)

但除非提示符是“mysql>”或“MySQL>”,否则它不起作用。