「mysql-shell」

认识

官网:https://dev.mysql.com/doc/mysql-shell/8.0/en/
文档:https://dev.mysql.com/doc/mysql-shell/8.0/en/
仓库:https://github.com/mysql/mysql-shell

MySQL Shell 是支持 MySQL Server 开发和管理的交互式界面,是 MySQL Server 的组件。支持 Javascript、Python、SQL 语言,可以使用 MySQL Shell 来执行数据查询和更新以及各种管理操作。

构建

下载 | https://dev.mysql.com/downloads/shell/
可以到官网下载 MySQL Shell。我们安装的版本使 1.0.9。

详细的安装过程都在源码目录下的 INSTALL 文件中,这里不再赘述,以下内容取自 INSTALL 文件,更多细节请阅读 INSTALL 文件:
Build Instructions for MySQL Shell

需要安装的依赖软件包如下
– cmake
– boost 1.59+,C++ 库
– libmysqlclient 5.7+
– protobuf 2.6.1
– zip (gnuwin32 in windows)
– python 2.6+
– MySQL Connector Python 2.1.3+ (for Python 2)

可选的依赖软件包
– gtest 1.7,用于单元测试
– v8 3.28.71.19,Javascript 引擎,安装 v8 时要注意版本。

使用源码开始编译

#!/bin/sh

# 1. 进入源码目录
mkdir bld
cd bld
cmake .. -DWITH_PROTOBUF=<path_to_protobuf> -DHAVE_PYTHON=1
make

以这种方式编译出来的 MySQL Shell 只支持 SQL 模式。

如果你希望支持 Javascript
JavaScript is enabled by satisfying the dependency with V8.
To build V8 follow the build V8 standard build instructions.
To support JavaScript on the MySQL Shell add the next flags to the CMake call:

-DV8_INCLUDE_DIR=<path_to_v8>/include
-DV8_LIB_DIR=<path_to_folder_containing_the_built_libraries>

如果你希望支持 Python
Python is enabled by satisfying the dependency with Python.
To support Python on the MySQL Shell add the next flags to the CMake call:

-DHAVE_PYTHON=1

指定 MySQL 的安装路径
如果 MySQL 的安装不符合 FHS,那你就要手动指定 MySQL 的安装路径了。
Specify the MySQL to be used (i.e. not the installed one) by adding the next parameter to the cmake call.
-DMYSQL_DIR=<path_to_mysql-folder>
Version 5.7 and above is recommended.
If MySQL is installed CMake may be able to find it even the parameter is not specified.
Use the parameter to specify the path to an uncompressed MySQL package.

安装的程序

mysqlsh,实际上,其仅只安装了这一个命令。

Error List

#1 Curses library not found. Please install appropriate package,

— Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:64 (MESSAGE):
Curses library not found. Please install appropriate package,

remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.

Call Stack (most recent call first):

cmake/readline.cmake:107 (FIND_CURSES)

cmake/readline.cmake:181 (MYSQL_USE_BUNDLED_EDITLINE)

CMakeLists.txt:177 (MYSQL_CHECK_EDITLINE)

原因:没有安装 Curses 头文件。顺便提一句,Curses 是用于在终端里显示 GUI 的。
解决:安装 libncurses5-dev,在不同的发行版了,名字可能不相同。

#2 PROTOBUF_PROTOC_EXECUTABLE-NOTFOUND

make[2]: *** No rule to make target ‘../mysqlxtest/PROTOBUF_PROTOC_EXECUTABLE-NOTFOUND’, needed by ‘mysqlxtest/mysqlx_notice.pb.cc’. Stop.
CMakeFiles/Makefile2:234: recipe for target ‘mysqlxtest/CMakeFiles/mysqlxtest.dir/all’ failed
make[1]: *** [mysqlxtest/CMakeFiles/mysqlxtest.dir/all] Error 2

原因:为了偷懒,安装 protobuf 时,从源里安装的是 libprotobuf-dev,而没有安装 protobuf-c-compiler
解决:安装 protobuf-c-compiler

参考

MySQL Shell User Guide
MySQL Shell Download Page