大网数据广告活动
服务器运维问答

Export Local MySQL Table Into Remote Database

· 52CE 我爱测

I am trying to export only some tables in a local database, into a remote database which has the same name of these tables + some other tables (I want to overwrite the remote database tables which has the same name with the local…

问题原文

原帖链接 · Madno · CC BY-SA 3.0

I am trying to export only some tables in a local database, into a remote database which has the same name of these tables + some other tables (I want to overwrite the remote database tables which has the same name with the local ones I have from my database, both databases are called wordpress).

After a bit of Google'ing, I thought the following command should work:

mysqldump -u USER --single-transaction --compress --order-by-primary --databases wordpress wp_posts wp_postmeta wp_comments wp_commentmeta wp_users wp_usermeta -pPASSWORD1 | mysql -u USER -pPASSWORD2 --port=REMOTE_PORT --host=REMOTE_HOST

But it gives me following error:

mysqldump: Got error: 1049: Unknown database 'wp_posts' when selecting the database

Why?

已采纳解答

原帖链接 · Mike · CC BY-SA 3.0

--databases lets you specify which dbs you want to dump so doing what you are doing you are telling it to dump all those databases which after wordpress are tables in the wordpress database.

You want this

mysqldump -u USER --single-transaction --order-by-primary wordpress wp_posts wp_postmeta wp_comments wp_commentmeta wp_users wp_usermeta -pPASSWORD1 | mysql -u USER -pPASSWORD2 --port=REMOTE_PORT --host=REMOTE_HOST wordpress

Just remove the --databases flag. I would also add the --compress flag to the mysql client to import. Also make sure you create the database on the remote side

CREATE DATABASE wordpress;

Here is a mysqldump help

Usage: mysqldump [OPTIONS] database [tables]
OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-10-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。