MySQL从远程数据库导入表(表结构+数据)

mysqldump -h '远程主机' -u远程数据库用户名 -p远程数据库密码 --compress --set-gtid-purged=OFF 远程数据库名 远程数据库表名 | mysql -h localhost -u本地数据库用户名 -p本地数据库密码 本地数据库名

解释:

--compress 压缩

--set-gtid-purged=OFF 之前没有加该选项,然后报错Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events.
ERROR 3546 (HY000) at line 24: @@GLOBAL.GTID_PURGED cannot be changed: the added gtid set must not overlap with @@GLOBAL.GTID_EXECUTED
mysqldump: Got errno 32 on write

具体什么意思没看懂,但是根据提示加了这个选项,导入成功

若想导入远程数据库的所有表,可将远程数据库表名更换为--tables选项

关于mysqldump的具体参数含义,可执行mysqldump --help查看

猜你喜欢

转载自blog.csdn.net/weixin_38823568/article/details/82768905