首页 > 解决方案 > 将数据从一个数据库中的表复制到 wordpress 数据库

问题描述

如何将数据库中的一个表中的数据复制到 wordpress 数据库中?所以我自己的数据库中的表被称为“文章”,我已经在我的本地机器上安装了 WordPress,它自动附带了表,还有一个名为“wp_posts”的表,我也试图在其中复制文章。所以我正在尝试将我创建的其他网站移动到 wordpress 网站,但我不想丢失所有已经创建的文章。我该怎么做?我已经尝试过了,但我得到了一个 SQL 语法错误。

INSERT INTO wp_seetheuniverse.dbo.wp_posts ('wp_title', 'wp_content')
SELECT 'title', 'content' FROM seetheuniverse.dbo.articles;

这是我得到的错误

ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '.wp_posts ('wp_title', 'wp_content') SELECT
'title', 'content' FROM seetheuniver' at line 1

标签: phpmysqlsqldatabasewordpress

解决方案


确保在 INTO 和 select 子句中有相应的列(数字和类型)

    INSERT INTO wp_seetheuniverse.dbo.wp_posts (col1, col2, col3)
    SELECT your_col1, your_col, your_col3 
    FROM seetheuniverse.dbo.articles;

不要在列名周围使用单引号,最终我们将反引号用于复合列名或保留字

INSERT INTO wp_seetheuniverse.wp_posts (wp_title, wp_content)
SELECT title, content FROM seetheuniverse.articles; 

并确保您使用的是正确的 database.schema.table 参考

INSERT INTO dbo.wp_seetheuniverse.wp_posts (wp_title, wp_content)
SELECT title, content FROM dbo.seetheuniverse.articles; 

推荐阅读