这是一个 Perl 脚本,可用于估算如果将 MySQL 数据库转换为使用 NDBCLUSTER 存储引擎时所需的空间量。与本节讨论的其他工具不同,它不需要访问 NDB Cluster(实际上没有理由需要访问)。但是,它确实需要访问存放待测试数据库的 MySQL 服务器。This is a Perl script that can be used to estimate the amount of
space that would be required by a MySQL database if it were
converted to use the NDBCLUSTER
storage engine. Unlike the other utilities discussed in this
section, it does not require access to an NDB Cluster (in fact,
there is no reason for it to do so). However, it does need to
access the MySQL server on which the database to be tested
resides.
ndb_size.pl 在 NDB 8.4.3 及更高版本中已被弃用,不再受支持。您应预料它将在未来的 NDB Cluster 发行版中被移除,并相应修改所有依赖此脚本的应用程序。ndb_size.pl is deprecated, and no longer supported, in NDB 8.4.3 and later. You should expect it to be removed from a future version of the NDB Cluster distribution, and modify any dependent applications accordingly.
要求Requirements
一个正在运行的 MySQL 服务器。服务器实例不必支持 NDB 集群。A running MySQL server. The server instance does not have to provide support for NDB Cluster.
Perl 的工作安装环境。A working installation of Perl.
DBI模块,如果你的 Perl 安装中尚未包含此模块,可以从 CPAN 获得。(许多 Linux 和其他操作系统分发版本都提供该库的自有软件包。)TheDBImodule, which can be obtained from CPAN if it is not already part of your Perl installation. (Many Linux and other operating system distributions provide their own packages for this library.)一个拥有必要权限的 MySQL 用户账户。如果你不想使用现有账户,可以通过使用
GRANT USAGE ON db_name.*创建一个账户即可——其中db_name是要检查的数据库名称。A MySQL user account having the necessary privileges. If you do not wish to use an existing account, then creating one usingGRANT USAGE ON—wheredb_name.*db_nameis the name of the database to be examined—is sufficient for this purpose.
ndb_size.pl 也可以在 MySQL 源代码的 storage/ndb/tools 中找到。ndb_size.pl can also be found in the MySQL
sources in storage/ndb/tools.
可以与 ndb_size.pl 一起使用的选项显示在下表中。表格之后是额外的描述。Options that can be used with ndb_size.pl are shown in the following table. Additional descriptions follow the table.
用法Usage
perl ndb_size.pl [--database={db_name|ALL}] [--hostname=host[:port]] [--socket=socket] \
[--user=user] [--password=password] \
[--help|-h] [--format={html|text}] \
[--loadqueries=file_name] [--savequeries=file_name]
默认情况下,该工具尝试分析服务器上的所有数据库。您可以使用 --database 选项指定单个数据库;默认行为可以通过使用 ALL 作为数据库名称来明确表示。您还可以使用 --excludedbs 选项并提供以逗号分隔的要跳过的数据库名称列表来排除一个或多个数据库。同样,您可以通过列出要跳过的特定表名并用逗号分隔,紧跟可选的 --excludetables 选项,实现对特定表的排除。可以使用 --hostname 指定主机名;默认是 localhost。您可以使用 host:port 格式在 --hostname 选项中指定主机的同时指定端口。默认端口号为 3306。如有必要,您也可以指定套接字;默认是 /var/lib/mysql.sock。可以使用相应的选项指定 MySQL 用户名和密码。也可以使用 --format 选项控制输出格式;该选项可以使用 html 或 text,默认值为 text。下面显示了文本输出的示例:
By default, this utility attempts to analyze all databases on
the server. You can specify a single database using the
--database option; the default behavior can be
made explicit by using ALL for the name of
the database. You can also exclude one or more databases by
using the --excludedbs option with a
comma-separated list of the names of the databases to be
skipped. Similarly, you can cause specific tables to be skipped
by listing their names, separated by commas, following the
optional --excludetables option. A host name
can be specified using --hostname; the default
is localhost. You can specify a port in
addition to the host using
host:port
format for the value of --hostname. The default
port number is 3306. If necessary, you can also specify a
socket; the default is /var/lib/mysql.sock.
A MySQL user name and password can be specified the
corresponding options shown. It also possible to control the
format of the output using the --format option;
this can take either of the values html or
text, with text being the
default. An example of the text output is shown here:
$> ndb_size.pl --database=test --socket=/tmp/mysql.sock
ndb_size.pl report for database: 'test' (1 tables)
--------------------------------------------------
Connected to: DBI:mysql:host=localhost;mysql_socket=/tmp/mysql.sock
Including information for versions: 4.1, 5.0, 5.1
test.t1
-------
DataMemory for Columns (* means varsized DataMemory):
Column Name Type Varsized Key 4.1 5.0 5.1
HIDDEN_NDB_PKEY bigint PRI 8 8 8
c2 varchar(50) Y 52 52 4*
c1 int(11) 4 4 4
-- -- --
Fixed Size Columns DM/Row 64 64 12
Varsize Columns DM/Row 0 0 4
DataMemory for Indexes:
Index Name Type 4.1 5.0 5.1
PRIMARY BTREE 16 16 16
-- -- --
Total Index DM/Row 16 16 16
IndexMemory for Indexes:
Index Name 4.1 5.0 5.1
PRIMARY 33 16 16
-- -- --
Indexes IM/Row 33 16 16
Summary (for THIS table):
4.1 5.0 5.1
Fixed Overhead DM/Row 12 12 16
NULL Bytes/Row 4 4 4
DataMemory/Row 96 96 48
(Includes overhead, bitmap and indexes)
Varsize Overhead DM/Row 0 0 8
Varsize NULL Bytes/Row 0 0 4
Avg Varside DM/Row 0 0 16
No. Rows 0 0 0
Rows/32kb DM Page 340 340 680
Fixedsize DataMemory (KB) 0 0 0
Rows/32kb Varsize DM Page 0 0 2040
Varsize DataMemory (KB) 0 0 0
Rows/8kb IM Page 248 512 512
IndexMemory (KB) 0 0 0
Parameter Minimum Requirements
------------------------------
* indicates greater than default
Parameter Default 4.1 5.0 5.1
DataMemory (KB) 81920 0 0 0
NoOfOrderedIndexes 128 1 1 1
NoOfTables 128 1 1 1
IndexMemory (KB) 18432 0 0 0
NoOfUniqueHashIndexes 64 0 0 0
NoOfAttributes 1000 3 3 3
NoOfTriggers 768 5 5 5
出于调试目的,可以将该脚本运行的查询所包含的 Perl 数组保存到使用 --savequeries 指定的文件中;在脚本执行期间要读取的此类数组文件可以使用 --loadqueries 指定。这些选项都没有默认值。
For debugging purposes, the Perl arrays containing the queries
run by this script can be read from the file specified using can
be saved to a file using --savequeries; a file
containing such arrays to be read during script execution can be
specified using --loadqueries. Neither of these
options has a default value.
要生成 HTML 格式的输出,请使用 --format 选项并将输出重定向到文件,如下所示:
To produce output in HTML format, use the
--format option and redirect the output to a
file, as shown here:
$> ndb_size.pl --database=test --socket=/tmp/mysql.sock --format=html > ndb_size.html
(如果不进行重定向,输出将发送到 stdout。)(Without the redirection, the output is sent to
stdout.)
该脚本的输出包括以下信息:The output from this script includes the following information:
为适应所分析的表所需的
DataMemory、IndexMemory、MaxNoOfTables、MaxNoOfAttributes、MaxNoOfOrderedIndexes和MaxNoOfTriggers配置参数的最小值。Minimum values for theDataMemory,IndexMemory,MaxNoOfTables,MaxNoOfAttributes,MaxNoOfOrderedIndexes, andMaxNoOfTriggersconfiguration parameters required to accommodate the tables analyzed.数据库中定义的所有表、属性、有序索引和唯一哈希索引的内存需求。Memory requirements for all of the tables, attributes, ordered indexes, and unique hash indexes defined in the database.
每个表和表行所需的
IndexMemory和DataMemory。TheIndexMemoryandDataMemoryrequired per table and table row.