MySQL Cluster Manager 8.0.31 用户手册  / 第 4 章使用 MySQL 集群管理器  /  3.3 启动MySQL Cluster Manager客户端

3.3 启动MySQL Cluster Manager客户端

本节介绍启动 MySQL Cluster Manager 客户端和连接到 MySQL Cluster Manager 代理。

MySQL Cluster Manager 1.3.6 包含一个命令行客户端 mcm,位于安装 bin目录中。可以使用下表中显示的任何一个选项调用 mcm :

表 3.3 mcm 命令行选项

长表 简写 描述
--help -? 显示mcm客户端选项
--version -V 显示 MySQL Cluster Manager 代理/客户端版本。
-W 显示 MySQL Cluster Manager 代理/客户端版本,以及 mcm使用的mysql版本。
--address -a 连接到 mcmd时使用的主机和可选端口, 格式为;默认是。host[:port]127.0.0.1:1862
--mysql-help -I 显示mysql客户端的帮助(见下文)。

MySQL Cluster Manager 使用的客户端/服务器协议是平台无关的。 您可以在任何可用的平台上使用mcm客户端连接到任何 MySQL Cluster Manager 代理。这意味着,例如,您可以使用 Microsoft Windows 上的mcm客户端连接到在 Linux 主机上运行的 MySQL Cluster Manager 代理。

mcm实际上充当 mysql客户端的包装器,它包含在捆绑的 MySQL Cluster 发行版中。不指定任何选项调用mcm等效于以下内容:

$> mysql -umcmd -psuper -h 127.0.0.1 -P 1862 --prompt="mcm>"

(这些选项-u-p值是硬编码的,无法更改。)这意味着您可以使用mysql客户端在mcm本身(甚至 mcmd)不可用的平台上运行 MySQL Cluster Manager 客户端会话。有关详细信息,请参阅使用mysql客户端连接到代理

如果您在启动 MySQL Cluster Manager 客户端会话时遇到问题,因为客户端无法连接,请参阅 无法连接到 [本地] MySQL 服务器,了解可能发生这种情况的某些原因,以及一些可能的解决方案的建议。

要结束客户端会话,请使用exitor quit命令(缩写形式:) \q。这些命令都不需要分隔符或终止符。

有关详细信息,请参阅第 4 章,MySQL Cluster Manager 客户端命令

使用mcm客户端连接到代理。  您可以通过调用mcm(或者,在 Windows 上, 调用mcm.exe) 来连接到 MySQL Cluster Manager 代理 。您可能还需要使用以下命令行选项指定主机名、端口号或两者:

  • --host=hostname-h[ ]hostname

    此选项采用要连接的主机的名称或 IP 地址。默认值是(在启动mcmlocalhost客户端会话时可能无法在所有平台上识别, 即使它适用于启动mysql客户端会话)。

    您应该记住,mcm客户端不执行主机名解析;任何名称解析信息都来自运行客户端的主机上的操作系统。因此,通常最好为此选项使用数字 IP 地址而不是主机名。

  • --port=portnumber-P[ ]portnumber

    This option specifies the TCP/IP port for the client to use. This must be the same port that is used by the MySQL Cluster Manager agent. As mentioned eslewhere, if no agent port is specified in the MySQL Cluster Manager agent configuration file (mcmd.ini), the default number of the port used by the MySQL Cluster Manager agent is 1862, which is also used by default by mcm.

mcm accepts additional mysql client options, some of which may possibly be of use for MySQL Cluster Manager client sessions. For example, the --pager option might prove helpful when the output of get contains too many rows to fit in a single screen. The --prompt option can be used to provide a distinctive prompt to help avoid confusion between multiple client sessions. However, options not shown in the current manual have not been extensively tested with mcm and so cannot be guaranteed to work correctly (or even at all). See mysql Client Options, for a complete listing and descriptions of all mysql client options.

Note

Like the mysql client, mcm also supports \G as a statement terminator which causes the output to be formatted vertically. This can be helpful when using a terminal whose width is restricted to some number of (typically 80) characters. See Chapter 4, MySQL Cluster Manager Client Commands, for examples.

Connecting to the agent using the mysql client.  As mentioned previously, mcm actually serves as a wrapper for the mysql client. In fact, a mysql client from any recent MySQL distribution (MySQL 5.1 or later) should work without any issues for connecting to mcmd. In addition, since the client/server protocol used by MySQL Cluster Manager is platform-independent, you can use a mysql client on any platform supported by MySQL. (This means, for example, that you can use a mysql client on Microsoft Windows to connect to a MySQL Cluster Manager agent that is running on a Linux host.) Connecting to the MySQL Cluster Manager agent using the mysql client is accomplished by invoking mysql and specifying a hostname, port number, username and password, using the following command-line options:

  • --host=hostname or -h[ ]hostname

    This option takes the name or IP address of the host to connect to. The default is localhost. Like the mcm client, the mysql client does not perform host name resolution, and relies on the host operating system for this task. For this reason, it is usually best to use a numeric IP address rather than a hostname for this option.

  • --port=portnumber or -P[ ]portnumber

    This option specifies the TCP/IP port for the client to use. This must be the same port that is used by the MySQL Cluster Manager agent. Although the default number of the port used by the MySQL Cluster Manager agent is 1862 (which is also used by default by mcm), this default value is not known to the mysql client, which uses port 3306 (the default port for the MySQL server) if this option is not specified when mysql is invoked.

    Thus, you must use the --port or -P option to connect to the MySQL Cluster Manager agent using the mysql client, even if the agent process is using the MySQL Cluster Manager default port, and even if the agent process is running on the same host as the mysql client. Unless the correct agent port number is supplied to it on startup, mysql is unable to connect to the agent.

  • --user=username or -u[ ]username

    Specifies the username for the user trying to connect. Currently, the only user permitted to connect is mcmd; this is hard-coded into the agent software and cannot be altered by any user. By default, the mysql client tries to use the name of the current system user on Unix systems and ODBC on Windows, so you must supply this option and the username mcmd when trying to access the MySQL Cluster Manager agent with the mysql client; otherwise, mysql cannot connect to the agent.

  • --password[=password] or -p[password]

    Specifies the password for the user trying to connect. If you use the short option form (-p), you must not leave a space between this option and the password. If you omit the password value following the --password or -p option on the command line, the mysql client prompts you for one.

    Specifying a password on the command line should be considered insecure. It is preferable that you either omit the password when invoking the client, then supply it when prompted, or put the password in a startup script or configuration file.

    Currently, the password is hard-coded as super, and cannot be changed or overridden by MySQL Cluster Manager users. Therefore, if you do not include the --password or -p option when invoking mysql, it cannot connect to the agent.

In addition, you can use the --prompt option to set the mysql client's prompt. This is recommended, since allowing the default prompt (mysql>) to be used could lead to confusion between a MySQL Cluster Manager client session and a MySQL client session.

Thus, you can connect to a MySQL Cluster Manager agent by invoking the mysql client on the same machine from the system shell in a manner similar to what is shown here.

$> mysql -h127.0.0.1 -P1862 -umcmd -p --prompt='mcm> '

For convenience, on systems where mcm itself is not available, you might even want to put this invocation in a startup script. On a Linux or similar system, this script might be named mcm-client.sh, with contents similar to what is shown here:

#!/bin/sh
/usr/local/mysql/bin/mysql -h127.0.0.1 -P1862 -umcmd -p --prompt='mcm> '

In this case, you could then start up a MySQL Cluster Manager client session using something like this in the system shell:

$> ./mcm-client

On Windows, you can create a batch file with a name such as mcm-client.bat containing something like this:

C:\mysql\bin\mysql.exe -umcmd -psuper -h localhost -P 1862 --prompt="mcm> "

(根据需要调整mysql.exe客户端可执行文件的路径以匹配其在系统上的位置。)

如果将此文件保存到方便的位置,例如 Windows 桌面,只需双击桌面上(或 Windows 资源管理器中)的相应文件图标即可启动 MySQL Cluster Manager 客户端会话;客户端会话在新的 cmd.exe (DOS) 窗口中打开。