本快速入门指南假定用户对 MySQL Shell 有一定的了解。以下部分为高级概述,更多信息请参阅 MySQL Shell 文档。MySQL Shell 是 MySQL 服务器的统一脚本接口。它支持 JavaScript 和 Python 脚本。SQL 是默认的处理模式。This quick-start guide assumes a certain level of familiarity with MySQL Shell. The following section is a high level overview, see the MySQL Shell documentation for more information. MySQL Shell is a unified scripting interface to MySQL Server. It supports scripting in JavaScript and Python. SQL is the default processing mode.
在安装并启动 MySQL 服务器后,将 MySQL Shell 连接到服务器实例。您需要知道计划连接的 MySQL 服务器实例的地址。为了能够将该实例用作文档存储,服务器实例必须安装 X 插件,并且您应使用 X 协议连接到服务器。例如,要连接到默认 X 协议端口 33060 上的实例 ds1.example.com,请使用网络字符串 。After you have installed and started MySQL server, connect
MySQL Shell to the server instance. You need to know the
address of the MySQL server instance you plan to connect to. To
be able to use the instance as a Document Store, the server
instance must have X Plugin installed and you should connect to
the server using X Protocol. For example to connect to the
instance user@ds1.example.com:33060ds1.example.com on the default
X Protocol port of 33060 use the network string
.user@ds1.example.com:33060
如果您使用经典 MySQL 协议连接到实例,例如使用默认的 port 3306 而不是 mysqlx_port,您 无法 使用本教程中显示的文档存储功能。例如,全局对象 db 将不会被填充。要使用文档存储,请始终使用 X 协议连接。If you connect to the instance using classic MySQL protocol, for
example by using the default
port of 3306 instead of the
mysqlx_port, you
cannot use the Document Store
functionality shown in this tutorial. For example the
db global object is not populated. To use
the Document Store, always connect using X Protocol.
如果 MySQL Shell 尚未运行,请打开终端窗口并输入:If MySQL Shell is not already running, open a terminal window and issue:
mysqlsh user@ds1.example.com:33060/world_x
或者,如果 MySQL Shell 已经在运行,请使用 \connect 命令输入:Alternatively, if MySQL Shell is already running use the
\connect command by issuing:
\connect user@ds1.example.com:33060/world_x
您需要指定要连接 MySQL Shell 的 MySQL 服务器实例的地址。例如在前面的示例中:You need to specify the address of the MySQL server instance which you want to connect MySQL Shell to. For example in the previous example:
user代表您的 MySQL 帐户的用户名。userrepresents the user name of your MySQL account.ds1.example.com是运行 MySQL 的服务器实例的主机名。请将其替换为您用作文档存储的 MySQL 服务器实例的主机名。ds1.example.comis the hostname of the server instance running MySQL. Replace this with the hostname of the MySQL server instance you are using as a Document Store.此会话的默认模式是
world_x。有关设置world_x模式的说明,请参见 第 22.3.2 节,“下载并导入 world_x 数据库”。The default schema for this session isworld_x. For instructions on setting up theworld_xschema, see Section 22.3.2, “Download and Import world_x Database”.
有关更多信息,请参见 第 6.2.5 节,“使用类似 URI 的字符串或键值对连接到服务器”。For more information, see Section 6.2.5, “Connecting to the Server Using URI-Like Strings or Key-Value Pairs”.
一旦 MySQL Shell 打开,mysql-js> 提示符表示此会话的活动语言是 SQL。Once MySQL Shell opens, the mysql-js> prompt
indicates that the active language for this session is SQL.
MYSQL SQL>
MySQL Shell 支持如下的输入行编辑:MySQL Shell supports input-line editing as follows:
左箭头 和 右箭头 键在当前输入行内水平移动。left-arrow and right-arrow keys move horizontally within the current input line.
上箭头 和 下箭头 键在之前输入的行集合中向上或向下移动。up-arrow and down-arrow keys move up and down through the set of previously entered lines.
退格键 删除光标前的字符,输入新字符会在光标位置插入这些字符。Backspace deletes the character before the cursor and typing new characters enters them at the cursor position.
回车键 将当前输入行发送到服务器。Enter sends the current input line to the server.
在命令解释器提示符下输入 mysqlsh --help,可查看命令行选项列表。Type mysqlsh --help at the prompt of your command interpreter for a list of command-line options.
mysqlsh --help
在 MySQL Shell 提示符下输入 \help,可查看可用命令及其描述。Type \help at the MySQL Shell prompt for a
list of available commands and their descriptions.
mysql-js> \help
输入 \help 后加命令名称,可获得单个 MySQL Shell 命令的详细帮助。例如,要查看 \connect 命令的帮助,请执行:Type \help followed by a command name for
detailed help about an individual MySQL Shell command. For
example, to view help on the \connect
command, issue:
mysql-js> \help \connect
请参阅 交互式代码执行,了解 MySQL Shell 中交互式代码执行的工作原理。See Interactive Code Execution for an explanation of how interactive code execution works in MySQL Shell.
请参阅 MySQL Shell 入门 了解会话和连接的替代方案。See Getting Started with MySQL Shell to learn about session and connection alternatives.