Window 环境 安装 Mycli
平时都用 图形化界面操作MySQL 如 navicat, workbench. 为了更专业一点也锻炼一下动手能力,现在打算换成命令行的方式操作。了解到 myclli这个工具。方便体验,就先在window环境装一个玩玩。
mycli 是一个 MySQL 命令行客户端工具,具有自动完成和语法突出显示功能。
它是基于 python 开发的一个工具,适合初学者或者对数据库熟悉但命令记不住的人群,能很好地克服记不住命令的困难。 mycli 官网 地址
一、Python 3 安装
-
官网下载地址(windows版本):Python Releases for Windows | Python.org
-
推荐下载 windows-installer-64 bit, embaddable-XXX前缀的是绿色免安装版
-
下载后直接双击exe文件,进入图形界面,安装模式选择 customize installation(用户自定义安装), 不建议勾选Add Python XX to PATH,勾选后去环境变量里找很难找到,安装完自己去手动添加环境变量即可,后续无脑next,记得换安装路径。
-
python 卸载,如果安装错了,重新点击刚刚下载的python安装exe,选择 uninstall 即可干净卸载,然后再重新安装。
-
安装完成后,配置好系统环境变量 ,python安装的目录,及其下一层级的 Scripts目录,注意把 windowsApps这个往下移动,否则配置好后,到cmd 命令行窗口输入 python 会奇怪的打开 window应用商店…
-
测试 python 安装: 打开cmd 命令行 输入
python
打印如下内容即安装完成,环境变量也生效了PS C:\Users\lvzb3> python Python 3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>
二、Mycli 安装
python 安装完成后,即可安装 mycli,
pip install mycli
。注意 官网参考资料中: Installing & Using MyCli on Windows - Code Wall, 使用的命令是pip install -U mycli
, 我在使用时,报错了:Could not install packages due to an OSError:XXXXXXX
。
D:\software\mycli>pip install mycli
Collecting mycli
Downloading mycli-1.26.1-py2.py3-none-any.whl (98 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 98.3/98.3 kB 131.0 kB/s eta 0:00:00
Collecting click>=7.0
Downloading click-8.1.3-py3-none-any.whl (96 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 96.6/96.6 kB 39.8 kB/s eta 0:00:00
Collecting cryptography==36.0.2
Downloading cryptography-36.0.2-cp36-abi3-win_amd64.whl (2.2 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.2/2.2 MB 15.5 kB/s eta 0:00:00
Collecting Pygments>=1.6
Downloading Pygments-2.14.0-py3-none-any.whl (1.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.1/1.1 MB 12.0 kB/s eta 0:00:00
Collecting prompt-toolkit<4.0.0,>=3.0.6
Downloading prompt_toolkit-3.0.36-py3-none-any.whl (386 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 386.4/386.4 kB 13.7 kB/s eta 0:00:00
Collecting PyMySQL>=0.9.2
Downloading PyMySQL-1.0.2-py3-none-any.whl (43 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 43.8/43.8 kB 11.7 kB/s eta 0:00:00
Collecting sqlparse<0.5.0,>=0.3.0
Downloading sqlparse-0.4.3-py3-none-any.whl (42 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.8/42.8 kB 11.1 kB/s eta 0:00:00
Collecting sqlglot>=5.1.3
Downloading sqlglot-10.4.2-py3-none-any.whl (199 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 199.1/199.1 kB 10.6 kB/s eta 0:00:00
Collecting configobj>=5.0.5
Downloading configobj-5.0.6.tar.gz (33 kB)
Preparing metadata (setup.py) ... done
Collecting cli-helpers[styles]>=2.2.1
Downloading cli_helpers-2.3.0-py3-none-any.whl (19 kB)
Collecting pyperclip>=1.8.1
Downloading pyperclip-1.8.2.tar.gz (20 kB)
Preparing metadata (setup.py) ... done
Collecting pyaes>=1.6.1
Downloading pyaes-1.6.1.tar.gz (28 kB)
Preparing metadata (setup.py) ... done
Collecting importlib-resources>=5.0.0
Downloading importlib_resources-5.10.2-py3-none-any.whl (34 kB)
Collecting cffi>=1.12
Downloading cffi-1.15.1-cp311-cp311-win_amd64.whl (179 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 179.0/179.0 kB 7.6 kB/s eta 0:00:00
Collecting tabulate[widechars]>=0.8.2
Downloading tabulate-0.9.0-py3-none-any.whl (35 kB)
Collecting colorama
Downloading colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Collecting six
Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting wcwidth
Downloading wcwidth-0.2.5-py2.py3-none-any.whl (30 kB)
Collecting pycparser
Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 118.7/118.7 kB 16.0 kB/s eta 0:00:00
Installing collected packages: wcwidth, sqlglot, pyperclip, pyaes, tabulate, sqlparse, six, PyMySQL, Pygments, pycparser, prompt-toolkit, importlib-resources, colorama, configobj, click, cffi, cryptography, cli-helpers, mycli
DEPRECATION: pyperclip is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
Running setup.py install for pyperclip ... done
DEPRECATION: pyaes is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
Running setup.py install for pyaes ... done
DEPRECATION: configobj is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
Running setup.py install for configobj ... done
Successfully installed PyMySQL-1.0.2 Pygments-2.14.0 cffi-1.15.1 cli-helpers-2.3.0 click-8.1.3 colorama-0.4.6 configobj-5.0.6 cryptography-36.0.2 importlib-resources-5.10.2 mycli-1.26.1 prompt-toolkit-3.0.36 pyaes-1.6.1 pycparser-2.21 pyperclip-1.8.2 six-1.16.0 sqlglot-10.4.2 sqlparse-0.4.3 tabulate-0.9.0 wcwidth-0.2.5
三、演示样例
C:\Users\lvzb3>mycli -u root -h 127.0.0.1
Password:
MySQL
mycli 1.26.1
Home: http://mycli.net
Bug tracker: https://github.com/dbcli/mycli/issues
Thanks to the contributor - Morgan Mitchell
MySQL root@127.0.0.1:(none)> show databases
+--------------------+
| Database |
+--------------------+
| demo |
| gefrm |
| information_schema |
| mysql |
| performance_schema |
| sys |
| workflow |
| xxl_job |
+--------------------+
8 rows in set
Time: 0.009s
MySQL root@127.0.0.1:(none)>
四、遇到的问题及解决
(一)pip install -U mycli
报错
解决: 使用 pip install mycli
D:\software\mycli>pip install -U mycli
Collecting mycli
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000019EB7ADCFD0>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/61/8c/4243cc0820dcb619edb30a997ef0a0697f7a80ef14341544de4dbac0fdc3/mycli-1.26.1-py2.py3-none-any.whl
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000019EB7ADD610>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/61/8c/4243cc0820dcb619edb30a997ef0a0697f7a80ef14341544de4dbac0fdc3/mycli-1.26.1-py2.py3-none-any.whl
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000019EB7ADDF90>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/61/8c/4243cc0820dcb619edb30a997ef0a0697f7a80ef14341544de4dbac0fdc3/mycli-1.26.1-py2.py3-none-any.whl
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000019EB7ADE750>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/61/8c/4243cc0820dcb619edb30a997ef0a0697f7a80ef14341544de4dbac0fdc3/mycli-1.26.1-py2.py3-none-any.whl
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000019EB7ADEF50>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)')': /packages/61/8c/4243cc0820dcb619edb30a997ef0a0697f7a80ef14341544de4dbac0fdc3/mycli-1.26.1-py2.py3-none-any.whl
ERROR: Could not install packages due to an OSError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/61/8c/4243cc0820dcb619edb30a997ef0a0697f7a80ef14341544de4dbac0fdc3/mycli-1.26.1-py2.py3-none-any.whl (Caused by ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x0000019EB7ADF710>, 'Connection to files.pythonhosted.org timed out. (connect timeout=15)'))
(二)less 不是内部或外部命令,也不是可运行的程序或批处理文件
解决:
- you can open up myclirc file located under
C:\Users\<username>\.myclirc
and setenable_pager = False
. This will turn off using less for output. 去C盘用户目录下的 .myclirc 把enable_pager = False
即可解决
参考资料
- Install (mycli.net)
- Installing & Using MyCli on Windows - Code Wall
- ‘less’ 不是内部或外部命令,也不是可运行的程序或批处理文件。 · Issue #1082 · dbcli/mycli · GitHub