MyCLI 主页: http://mycli.net/
1、MyCLI:一个支持自动补全和语法高亮的MySQL客户端
MyCLI 是一个易于使用的命令行客户端,可用于受欢迎的数据库管理系统 MySQL、MariaDB 和 Percona,支持自动补全和语法高亮。它是使用 prompt_toolkit 库写的,需要 Python 2.7、3.3、3.4、3.5 和 3.6 的支持。MyCLI 还支持通过 SSL 安全连接到 MySQL 服务器。
2、MyCLI 的特性:
1、当你第一次使用它的时候,将会自动创建一个文件 ~/.myclirc
2、当输入 SQL 的关键词和数据库中的表、视图和列时,支持自动补全。
3、默认情况下也支持智能补全,能根据上下文的相关性提供补全建议。
比如: SELECT * FROM <Tab> - 这将显示出数据库中的表名。 SELECT * FROM users WHERE <Tab> - 这将简单的显示出列名称。
4、通过使用 Pygents 支持语法高亮
5、支持 SSL 连接
6、提供多行查询支持
7、它可以将每一个查询和输出记录到一个文件中(默认情况下禁用)。
8、允许保存收藏一个查询(使用 \fs 别名 保存一个查询,并可使用 \f 别名 运行它)。
9、支持 SQL 语句执行和表查询计时
10、以更吸引人的方式打印表格数据
3、如何在 Linux 上为 MySQL 和 MariaDB 安装 MyCLI?
在 Debian/Ubuntu 发行版上,你可以很容易的像下面这样使用 apt 命令 来安装 MyCLI 包:
$ sudo apt-get update $ sudo apt-get install mycli
同样,在 Fedora 22+ 上也有 MyCLI 的可用包,你可以像下面这样使用 dnf 命令 来安装它:
$ sudo dnf install mycli
对于其他 Linux 发行版,比如 RHEL/CentOS,你需要使用 Python 的 pip 工具来安装 MyCLI。首先,使用下面的命令来安装 pip:
1、首先安装python-pip
使用yum安装python-pip时找不到该软件包,所以我们先安装拓展源。
[root@bogon ~]# yum -y install epel-release
2、然后安装python-pip
[root@bogon ~]# yum -y install python-pip
3、清除一下cache
[root@bogon ~]# yum clean all 已加载插件:fastestmirror, langpacks 正在清理软件源: base epel extras updates Cleaning up everything Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos Cleaning up list of fastest mirrors
4、现在安装完python-pip了,可以安装mycli了。
[root@bogon ~]# pip install mycli Collecting mycli Downloading mycli-1.16.0-py2.py3-none-any.whl (54kB) 100% |████████████████████████████████| 61kB 242kB/s Collecting click>=4.1 (from mycli) Downloading click-6.7-py2.py3-none-any.whl (71kB) 100% |████████████████████████████████| 71kB 624kB/s Requirement already satisfied (use --upgrade to upgrade): cryptography>=1.0.0 in /usr/lib64/python2.7/site-packages (from mycli) Collecting sqlparse<0.3.0,>=0.2.2 (from mycli) Downloading sqlparse-0.2.4-py2.py3-none-any.whl Collecting PyMySQL>=0.6.7 (from mycli) Downloading PyMySQL-0.8.0-py2.py3-none-any.whl (83kB) 100% |████████████████████████████████| 92kB 776kB/s Collecting prompt-toolkit<1.1.0,>=1.0.10 (from mycli) Downloading prompt_toolkit-1.0.15-py2-none-any.whl (247kB) 100% |████████████████████████████████| 256kB 731kB/s Collecting configobj>=5.0.5 (from mycli) Downloading configobj-5.0.6.tar.gz Collecting cli-helpers[styles]>=1.0.1 (from mycli) Downloading cli_helpers-1.0.1-py2-none-any.whl Collecting Pygments>=1.6 (from mycli) Downloading Pygments-2.2.0-py2.py3-none-any.whl (841kB) 100% |████████████████████████████████| 849kB 380kB/s Requirement already satisfied (use --upgrade to upgrade): idna>=2.0 in /usr/lib/python2.7/site-packages (from cryptography>=1.0.0->mycli) Requirement already satisfied (use --upgrade to upgrade): pyasn1>=0.1.8 in /usr/lib/python2.7/site-packages (from cryptography>=1.0.0->mycli) Requirement already satisfied (use --upgrade to upgrade): six>=1.4.1 in /usr/lib/python2.7/site-packages (from cryptography>=1.0.0->mycli) Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/lib/python2.7/site-packages (from cryptography>=1.0.0->mycli) Requirement already satisfied (use --upgrade to upgrade): enum34 in /usr/lib/python2.7/site-packages (from cryptography>=1.0.0->mycli) Requirement already satisfied (use --upgrade to upgrade): ipaddress in /usr/lib/python2.7/site-packages (from cryptography>=1.0.0->mycli) Requirement already satisfied (use --upgrade to upgrade): cffi>=1.4.1 in /usr/lib64/python2.7/site-packages (from cryptography>=1.0.0->mycli) Collecting wcwidth (from prompt-toolkit<1.1.0,>=1.0.10->mycli) Downloading wcwidth-0.1.7-py2.py3-none-any.whl Collecting tabulate>=0.8.0 (from cli-helpers[styles]>=1.0.1->mycli) Downloading tabulate-0.8.2.tar.gz (45kB) 100% |████████████████████████████████| 51kB 2.5MB/s Collecting terminaltables>=3.0.0 (from cli-helpers[styles]>=1.0.1->mycli) Downloading terminaltables-3.1.0.tar.gz Collecting backports.csv>=1.0.0 (from cli-helpers[styles]>=1.0.1->mycli) Downloading backports.csv-1.0.5-py2.py3-none-any.whl Requirement already satisfied (use --upgrade to upgrade): pycparser in /usr/lib/python2.7/site-packages (from cffi>=1.4.1->cryptography>=1.0.0->mycli) Installing collected packages: click, sqlparse, PyMySQL, wcwidth, prompt-toolkit, configobj, tabulate, terminaltables, backports.csv, Pygments, cli-helpers, mycli Found existing installation: configobj 4.7.2 DEPRECATION: Uninstalling a distutils installed project (configobj) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project. Uninstalling configobj-4.7.2: Successfully uninstalled configobj-4.7.2 Running setup.py install for configobj ... done Running setup.py install for tabulate ... done Running setup.py install for terminaltables ... done Successfully installed PyMySQL-0.8.0 Pygments-2.2.0 backports.csv-1.0.5 cli-helpers-1.0.1 click-6.7 configobj-5.0.6 mycli-1.16.0 prompt-toolkit-1.0.15 sqlparse-0.2.4 tabulate-0.8.2 terminaltables-3.1.0 wcwidth-0.1.7 You are using pip version 8.1.2, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command.
测试:
[root@bogon ~]# mycli -uroot -p123456 Version: 1.16.0 Chat: https://gitter.im/dbcli/mycli Mail: https://groups.google.com/forum/#!forum/mycli-users Home: http://mycli.net Thanks to the contributor - Anonymous mysql root@localhost:(none)> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set Time: 0.009s mysql root@localhost:(none)>
自动补全(对于关键词和 SQL 函数可以进行简单的自动补全)
智能补全 (当输入 FROM 关键词以后会进行表名称的补全)
别名支持(当表的名称设置别名以后,也支持列名称的补全)
语法高亮(支持 MySQL 语法高亮 )
格式化 SQL 的输出(MySQL 的输出会通过 less 命令[1] 进行格式化输出)
更多使用选项,请输入:
$ mycli --help
本文为崔凯原创文章,转载无需和我联系,但请注明来自冷暖自知一抹茶ckhttp://www.cksite.cn