如何将MySQL数据库a的表中的行添加到数据库B中的现有表中

如何将MySQL数据库a的表中的行添加到数据库B中的现有表中,mysql,database,mysql-workbench,Mysql,Database,Mysql Workbench,我正在使用MySQL。 我在数据库a中有一个“customers”表(位于服务器上) 我想将它们添加到数据库B(位于本地主机上)的customer表中,而不删除任何内容 一般来说,我对SQL命令或MySQL非常陌生,所以请尽可能多地解释。 如果你需要更多的信息,我会编辑文章并添加 (我有MySQL工作台) 谢谢 只需在本地主机上使用: mysqldump -u YOUR_DATABASE_USER -p YOUR_DATABASE_PASS -h YOUR_SERVER_IP databaseA

我正在使用MySQL。 我在数据库a中有一个“customers”表(位于服务器上)

我想将它们添加到数据库B(位于本地主机上)的customer表中,而不删除任何内容

一般来说,我对SQL命令或MySQL非常陌生,所以请尽可能多地解释。 如果你需要更多的信息,我会编辑文章并添加

(我有MySQL工作台)


谢谢

只需在本地主机上使用:

mysqldump -u YOUR_DATABASE_USER -p YOUR_DATABASE_PASS -h YOUR_SERVER_IP databaseA customers > customer.sql
mysql -u YOUR_DATABASE_USER -p YOUR_DATABASE_PASS databaseB < customer.sql
mysqldump-u YOUR_DATABASE\u USER-p YOUR_DATABASE\u PASS-h YOUR_SERVER\u IP databaseA customers>customer.sql
mysql-u YOUR_DATABASE\u USER-p YOUR_DATABASE\u PASS databaseB
PD:如果需要一些解释,请在服务器(DB A)上告诉我:

# Sets our database as default, so we wont have to write `database`.`table` in the consecutive queries.
# Replace *database* with your database name. 
USE *database*;

# Makes a copy of the customers table - named customers_export.
# This copy contains all the fields and rows from the original table (without indexes),
# and if you want, you can add a WHERE clause to filter out some data
CREATE TABLE `customers_export` SELECT * FROM `customers`;
因为您使用的是mysql_workbench,所以通过选择相关数据库和customers_导出表来进行数据导出(在管理部分)

# Set as default
USE *database*;

# If the data you want to import contains *NO* collisions (same primary or unique values in both tables), the structure and table name is the same
INSERT INTO `customers` SELECT * FROM `customers_export`;
本地主机(DB B)上的

# Sets our database as default, so we wont have to write `database`.`table` in the consecutive queries.
# Replace *database* with your database name. 
USE *database*;

# Makes a copy of the customers table - named customers_export.
# This copy contains all the fields and rows from the original table (without indexes),
# and if you want, you can add a WHERE clause to filter out some data
CREATE TABLE `customers_export` SELECT * FROM `customers`;
假设数据库名称相同(否则需要更改转储文件中的数据库名称),通过选择我们在上一步中导出的转储文件来执行数据导入/还原。 这将创建customer_导出表

# Set as default
USE *database*;

# If the data you want to import contains *NO* collisions (same primary or unique values in both tables), the structure and table name is the same
INSERT INTO `customers` SELECT * FROM `customers_export`;
我们完成了。
如果确实存在冲突,或者您希望播放更改列名、某些值等-您需要修改select语句或更新customers\u导出表以满足您的需要

另外,在第二台服务器上备份customers表,以防insert出错


最后-删除两台服务器上的customers\u export表。

是否只想从服务器迁移到客户端。^是。从服务器到本地主机。我是否同时运行它们?还是一个接一个?如果我有一个定义为index和AI的ID,会有区别吗?你需要同时运行这两个ID,首先
mysqldump
将所有数据转储到一个sql文件,然后
mysql
插入本地表“如果我有一个定义为index和AI的ID,会有区别吗”不明白你在问什么:(,请解释我有一个id行,该行具有自动递增功能。如果两个表中的id相同,是否会产生任何问题?表(localhost)中的所有数据都将消失