我想从第二个 MySQL 数据库中选择数据,以便将数据从一台服务器迁移到另一台服务器。
我正在寻找类似的语法
从用户名中选择 *:[电子邮件受保护]
这可能吗?我可以使用链接服务器在 Microsoft SQL Server 中执行此操作,因此我假设它在 MySQL 中也是可能的。
I would like to select data from a second MySQL database in order to migrate data from one server to another.
I'm looking for syntax like
SELECT * FROM username:[email protected]
Is this possible? I would be able to do this in Microsoft SQL Server using linked servers, so I'm assuming it's possible in MySQL as well.
发布评论
评论(3)
您可以使用
FEDERATED
存储引擎创建表:基本上,它将充当远程
tableName
的视图。You can create a table using
FEDERATED
storage engine:Basically, it will serve as a view over the remote
tableName
.通常您可以采取两种方法,尽管它们听起来都不像您所追求的:
使用复制并设置两个数据库之间的主从关系。
简单地转储数据(使用命令行mysqldump工具)从第一个数据库并将其导入到第二个数据库中。
然而,尽管您可以通过 mysqldump 指定特定的表,但这两种方法最终都会迁移所有数据(即:不是子集)。此外,如果您使用 mysqldump 方法并且不使用 InnoDB,则需要确保在创建转储时源数据库未被使用(即:具有完整性)。
There are generally two approaches you can take, although neither of them sound like what you're after:
Use replication and set up a master/slave relationship between the two databases.
Simply dump the data (using the command line mysqldump tool) from the 1st database and import it into the 2nd.
However, both of these will ultimately migrate all of the data (i.e.: not a subset), although you can specify specific table(s) via mysqldump. Additionally, if you use the mysqldump approach and you're not using InnoDB you'll need to ensure that the source database isn't in use (i.e.: has integrity) when the dump is created.
您不能直接执行此操作,但正如其他人在评论中提到的那样,您可以使用 mysqldump 将表的内容导出为 SQL 脚本。
此时,您可以在新服务器上运行脚本来创建表,或者如果需要对数据进行更多操作,则将该数据导入到新服务器上具有不同名称的表中,然后编写查询来复制数据从那里。
You can't do this directly, but as someone else alluded to in a comment, you can use
mysqldump
to export the contents of a table as a SQL script.At that point you could run the script on the new server to create the table, or if more manipulation of the data is required, import that data into a table with a different name on the new server, then write a query to copy the data from there.