IMPORT TABLE FROMsdi_file
[,sdi_file
] ...
The IMPORT TABLE
statement imports MyISAM
tables based on information contained in .sdi
(serialized dictionary information) metadata files. IMPORT TABLE
语句根据.sdi
(序列化字典信息)元数据文件中包含的信息导入MyISAM
表。IMPORT TABLE
requires the FILE
privilege to read the .sdi
and table content files, and the CREATE
privilege for the table to be created.IMPORT TABLE
需要FILE
权限来读取.sdi
和表内容文件,并且需要创建表的创建权限。
Tables can be exported from one server using mysqldump to write a file of SQL statements and imported into another server using mysql to process the dump file. 可以使用mysqldump从一台服务器导出表来编写SQL语句文件,然后使用mysql
将表导入另一台服务器来处理转储文件。IMPORT TABLE
provides a faster alternative using the “raw” table files.IMPORT TABLE
使用“原始”表文件提供了更快的替代方法。
Prior to import, the files that provide the table content must be placed in the appropriate schema directory for the import server, and the 导入之前,提供表内容的文件必须放置在导入服务器的相应架构目录中,.sdi
file must be located in a directory accessible to the server. .sdi
文件必须位于服务器可以访问的目录中。For example, the 例如,可以将.sdi
file can be placed in the directory named by the secure_file_priv
system variable, or (if secure_file_priv
is empty) in a directory under the server data directory..sdi
文件放在由secure_file_priv
系统变量命名的目录中,或者(如果secure_file_priv
为空)放在服务器数据目录下的目录中。
The following example describes how to export 下面的示例描述如何从一台服务器的MyISAM
tables named employees
and managers
from the hr
schema of one server and import them into the hr
schema of another server. hr
架构导出名为employees
和managers
的MyISAM
表,并将它们导入另一台服务器的hr
架构。The example uses these assumptions (to perform a similar operation on your own system, modify the path names as appropriate):该示例使用这些假设(要在自己的系统上执行类似的操作,请根据需要修改路径名):
For the export server, 对于导出服务器,export_basedir
represents its base directory, and its data directory is
.export_basedir
/dataexport_basedir
表示其基本目录,其数据目录为export_basedir/data
。
For the import server, 对于导入服务器,import_basedir
represents its base directory, and its data directory is
.import_basedir
/dataimport_basedir
表示其基本目录,其数据目录为import_basedir/data
。
Table files are exported from the export server into the 表文件从导出服务器导出到/tmp/export
directory and this directory is secure (not accessible to other users)./tmp/export
目录,并且该目录是安全的(其他用户无法访问)。
The import server uses 导入服务器使用/tmp/mysql-files
as the directory named by its secure_file_priv
system variable./tmp/mysql-files
作为其secure_file_priv
系统变量命名的目录。
To export tables from the export server, use this procedure:要从导出服务器导出表,请使用以下步骤:
Ensure a consistent snapshot by executing this statement to lock the tables so that they cannot be modified during export:通过执行以下语句锁定表以确保快照的一致性,以便在导出期间无法修改这些表:
mysql> FLUSH TABLES hr.employees, hr.managers WITH READ LOCK;
While the lock is in effect, the tables can still be used, but only for read access.当锁生效时,表仍然可以使用,但只能用于读取访问。
At the file system level, copy the 在文件系统级别,将.sdi
and table content files from the hr
schema directory to the secure export directory:.sdi
和表内容文件从hr
架构目录复制到安全导出目录:
The .sdi
file is located in the hr
schema directory, but might not have exactly the same basename as the table name. .sdi
文件位于hr
架构目录中,但可能没有与表名完全相同的基本名。For example, the 例如,.sdi
files for the employees
and managers
tables might be named employees_125.sdi
and managers_238.sdi
.employees
表和managers
表的.sdi
文件可能命名为employees_125.sdi
和managers_238.sdi
。
For a 对于MyISAM
table, the content files are its .MYD
data file and .MYI
index file.MyISAM
表,内容文件是其.MYD
数据文件和.MYI
索引文件。
Given those file names, the copy commands look like this:给定这些文件名,copy命令如下所示:
shell>cd
shell>export_basedir
/data/hrcp employees_125.sdi /tmp/export
shell>cp managers_238.sdi /tmp/export
shell>cp employees.{MYD,MYI} /tmp/export
shell>cp managers.{MYD,MYI} /tmp/export
Unlock the tables:解锁表:
mysql> UNLOCK TABLES;
To import tables into the import server, use this procedure:要将表导入导入导入服务器,请使用以下过程:
The import schema must exist. 导入架构必须存在。If necessary, execute this statement to create it:如有必要,请执行以下语句来创建它:
mysql> CREATE SCHEMA hr;
At the file system level, copy the 在文件系统级别,将.sdi
files to the import server secure_file_priv
directory, /tmp/mysql-files
. .sdi
文件复制到import server secure_file_priv
目录/tmp/mysql-files
。Also, copy the table content files to the 另外,将表内容文件复制到hr
schema directory:hr
架构目录:
shell>cd /tmp/export
shell>cp employees_125.sdi /tmp/mysql-files
shell>cp managers_238.sdi /tmp/mysql-files
shell>cp employees.{MYD,MYI}
shell>import_basedir
/data/hrcp managers.{MYD,MYI}
import_basedir
/data/hr
Import the tables by executing an 通过执行IMPORT TABLE
statement that names the .sdi
files:Import TABLE
语句来导入表,该语句将.sdi
文件命名为:
mysql>IMPORT TABLE FROM
'/tmp/mysql-files/employees.sdi',
'/tmp/mysql-files/managers.sdi';
The 如果.sdi
file need not be placed in the import server directory named by the secure_file_priv
system variable if that variable is empty; it can be in any directory accessible to the server, including the schema directory for the imported table. secure_file_priv
系统变量指定的导入服务器目录为空,则不需要将.sdi
文件放在该目录中;它可以位于服务器可访问的任何目录中,包括导入表的架构目录。If the 但是,如果.sdi
file is placed in that directory, however, it may be rewritten; the import operation creates a new .sdi
file for the table, which overwrites the old .sdi
file if the operation uses the same file name for the new file..sdi
文件放在该目录中,它可能会被重写;导入操作为表创建一个新的.sdi
文件,如果操作对新文件使用相同的文件名,则会覆盖旧的.sdi
文件。
Each 每个sdi_file
value must be a string literal that names the .sdi
file for a table or is a pattern that matches .sdi
files. sdi_file
值必须是一个为表命名.sdi
文件的字符串文字,或者是一个与.sdi
文件匹配的模式。If the string is a pattern, any leading directory path and the 如果字符串是一个模式,则任何前导目录路径和.sdi
file name suffix must be given literally. .sdi
文件名后缀必须按字面给出。Pattern characters are permitted only in the base name part of the file name:仅允许在文件名的基名称部分使用模式字符:
?
matches any single character匹配任何单个字符
*
matches any sequence of characters, including no characters匹配任何字符序列,不包括任何字符
Using a pattern, the previous 使用模式,前面的IMPORT TABLE
statement could have been written like this (assuming that the /tmp/mysql-files
directory contains no other .sdi
files matching the pattern):IMPORT TABLE
语句可以这样编写(假设/tmp/mysql-files
目录不包含与模式匹配的其他.sdi
文件):
IMPORT TABLE FROM '/tmp/mysql-files/*.sdi';
To interpret the location of 为了解释.sdi
file path names, the server uses the same rules for IMPORT TABLE
as the server-side rules for LOAD DATA
(that is, the non-LOCAL
rules). .sdi
文件路径名的位置,服务器使用与加载数据的服务器端规则(即非本地规则)相同的IMPORT TABLE
规则。See Section 13.2.7, “LOAD DATA Statement”, paying particular attention to the rules used to interpret relative path names.请参阅第13.2.7节,“加载数据语句”,特别注意用于解释相对路径名的规则。
如果找不到IMPORT TABLE
fails if the .sdi
or table files cannot be located. .sdi
或表文件,则IMPORT TABLE
失败。After importing a table, the server attempts to open it and reports as warnings any problems detected. 导入表后,服务器将尝试打开它,并将检测到的任何问题报告为警告。To attempt a repair to correct any reported issues, use 要尝试修复以更正任何报告的问题,请使用REPAIR TABLE
.REPAIR TABLE
。
IMPORT TABLE
is not written to the binary log.IMPORT TABLE
未写入二进制日志。
IMPORT TABLE
applies only to non-TEMPORARY
MyISAM
tables. IMPORT TABLE
仅适用于非临时MyISAM
表。It does not apply to tables created with a transactional storage engine, tables created with 它不适用于使用事务存储引擎创建的表、使用CREATE TEMPORARY TABLE
, or views.CREATE TEMPORARY TABLE
创建的表或视图。
An 导入操作中使用的.sdi
file used in an import operation must be generated on a server with the same data dictionary version and sdi version as the import server. .sdi
文件必须在与导入服务器具有相同数据字典版本和sdi版本的服务器上生成。The version information of the generating server is found in the 生成服务器的版本信息位于.sdi
file:.sdi
文件中:
{ "mysqld_version_id":80019, "dd_version":80017, "sdi_version":80016, ... }
To determine the data dictionary and sdi version of the import server, you can check the 要确定导入服务器的数据字典和sdi版本,可以检查导入服务器上最近创建的表的.sdi
file of a recently created table on the import server..sdi
文件。
The table data and index files must be placed in the schema directory for the import server prior to the import operation, unless the table as defined on the export server uses the 在导入操作之前,表数据和索引文件必须放置在导入服务器的架构目录中,除非导出服务器上定义的表使用DATA DIRECTORY
or INDEX DIRECTORY
table options. DATA DIRECTORY
或INDEX DIRECTORY
表选项。In that case, modify the import procedure using one of these alternatives before executing the 在这种情况下,在执行IMPORT TABLE
statement:import TABLE
语句之前,请使用以下替代方法之一修改导入过程:
Put the data and index files into the same directory on the import server host as on the export server host, and create symlinks in the import server schema directory to those files.将数据和索引文件放入导入服务器主机上与导出服务器主机上相同的目录中,并在导入服务器架构目录中创建指向这些文件的符号链接。
Put the data and index files into an import server host directory different from that on the export server host, and create symlinks in the import server schema directory to those files. 将数据和索引文件放入不同于导出服务器主机的导入服务器主机目录中,并在导入服务器架构目录中创建指向这些文件的符号链接。In addition, modify the 另外,修改.sdi
file to reflect the different file locations..sdi
文件以反映不同的文件位置。
Put the data and index files into the schema directory on the import server host, and modify the 将数据和索引文件放入导入服务器主机上的schema目录,并修改.sdi
file to remove the data and index directory table options..sdi
文件以删除数据和索引目录表选项。
Any collation IDs stored in the 存储在.sdi
file must refer to the same collations on the export and import servers..sdi
文件中的任何排序规则ID都必须引用导出和导入服务器上的相同排序规则。
Trigger information for a table is not serialized into the table 表的触发器信息没有序列化到表.sdi
file, so triggers are not restored by the import operation..sdi
文件中,因此导入操作不会还原触发器。
Some edits to an 在执行.sdi
file are permissible prior to executing the IMPORT TABLE
statement, whereas others are problematic or may even cause the import operation to fail:IMPORT TABLE
语句之前,允许对.sdi
文件进行某些编辑,而其他编辑则有问题,甚至可能导致导入操作失败:
Changing the data directory and index directory table options is required if the locations of the data and index files differ between the export and import servers.如果数据和索引文件的位置在导出服务器和导入服务器之间不同,则需要更改数据目录和索引目录表选项。
Changing the schema name is required to import the table into a different schema on the import server than on the export server.需要更改架构名称才能将表导入导入导入服务器上与导出服务器上不同的架构。
Changing schema and table names may be required to accommodate differences between file system case-sensitivity semantics on the export and import servers or differences in 可能需要更改架构和表名以适应导出和导入服务器上的文件系统区分大小写语义之间的差异,或者在lower_case_table_names
settings. lower_case_table_names
设置中的差异。Changing the table names in the 更改.sdi
file may require renaming the table files as well..sdi
文件中的表名可能还需要重命名表文件。
In some cases, changes to column definitions are permitted. 在某些情况下,允许更改列定义。Changing data types is likely to cause problems.更改数据类型可能会导致问题。