将Drupal数据库表数据导入Wordpress数据库

时间:2018-09-05 12:39:17

标签: wordpress

我在WordPress上拥有当前的工作网站。我想从已在另一台服务器上运行drupal的数据库中导入数据。我如何将所有数据从drupal站点中的表导入到wordpress中当前工作的网站数据库中。请帮助我

1 个答案:

答案 0 :(得分:0)

第一个选择:将您的Drupal数据库迁移到WordPress的步骤和适用的查询:

1. Make a backup of both your Drupal and WordPress databases.

2. Before converting Drupal to WordPress, make sure that in your original Drupal install the taxonomies are correctly labeled. Step 11 will further discuss fixing taxonomy.

3. Create a new WordPress installation in a different database
from your Drupal installation. Name the different databases
‘drupal’ and ‘wordpress’.

4. Clear out previous content from the WordPress database by
running this command in your database’s SQL queries tab in
phpmyadmin.
TRUNCATE TABLE wordpress.wp_comments;
TRUNCATE TABLE wordpress.wp_links;
TRUNCATE TABLE wordpress.wp_postmeta;
TRUNCATE TABLE wordpress.wp_posts;
TRUNCATE TABLE wordpress.wp_term_relationships;
TRUNCATE TABLE wordpress.wp_term_taxonomy;
TRUNCATE TABLE wordpress.wp_terms;

5. Apply this code to convert over multiple users.
DELETE FROM wordpress.wp_users WHERE ID > 1;
DELETE FROM wordpress.wp_usermeta WHERE user_id > 1;

6. To migrate over tags, use the following code...
(To ensure duplicate names don’t get lost, make sure that the
Drupal term_data table has been cleaned of all duplicate names.)
REPLACE INTO wordpress.wp_terms
(term_id, `name`, slug, term_group)
SELECT DISTINCT
d.tid,
d.name,
REPLACE(LOWER(d.name), ' ', '_'), 0
FROM drupal.term_data d
INNER JOIN drupal.term_hierarchy h
USING(tid)
WHERE (1
)
;
INSERT INTO wordpress.wp_term_taxonomy
(term_id, taxonomy, description, parent)
SELECT DISTINCT
d.tid `term_id`,
'post_tag' `taxonomy`,
d.description `description`,
h.parent `parent`
FROM drupal.term_data d
INNER JOIN drupal.term_hierarchy h
USING(tid)
INNER JOIN drupal.term_node n
USING(tid)
WHERE (1
)
;

7. To convert over posts, apply the following query:
INSERT INTO wordpress.wp_posts
(id, post_author, post_date, post_content, post_title,
post_excerpt, post_name, post_modified, post_type,
`post_status`)
SELECT DISTINCT
n.nid `id`,
n.uid `post_author`,
FROM_UNIXTIME(n.created) `post_date`,
r.body `post_content`,
n.title `post_title`,
r.teaser `post_excerpt`,
IF(SUBSTR(a.dst, 11, 1) = '/', SUBSTR(a.dst, 12),
a.dst) `post_name`,
FROM_UNIXTIME(n.changed) `post_modified`,
n.type `post_type`,
IF(n.status = 1, 'publish', 'private') `post_status` FROM
drupal.node n
INNER JOIN drupal.node_revisions r
USING(vid)
LEFT OUTER JOIN drupal.url_alias a
ON a.src = CONCAT('node/', n.nid)
# If applicable, add more Drupal content types below.
WHERE n.type IN ('post', 'page', 'blog')
;
*If your Drupal installation has multiple post types, be sure to
add the name of the post type into this line: WHERE n.type IN
(‘post’, ‘page’, ‘blog’). Failure to do so will result in not all posts
types being converted over.

8. To combine post types in WordPress, run this script:
UPDATE wordpress.wp_posts
SET post_type = 'post' WHERE
post_type IN ('blog') ;

9. To define the post/tag relationship, apply the following:
INSERT INTO wordpress.wp_term_relationships (object_
id, term_taxonomy_id)
SELECT DISTINCT nid, tid FROM drupal.term_node
;
# Update tag counts.
UPDATE wp_term_taxonomy tt
SET `count` = (
SELECT COUNT(tr.object_id)
FROM wp_term_relationships tr
WHERE tr.term_taxonomy_id = tt.term_taxonomy_id
)
;

10.Apply this query to migrate comments:
INSERT INTO wordpress.wp_comments
(comment_post_ID, comment_date, comment_content,
comment_parent, comment_author,
comment_author_email, comment_author_url, comment_
approved)
SELECT DISTINCT
nid, FROM_UNIXTIME(timestamp), comment, thread, name,
mail, homepage, ((status + 1) % 2)
FROM drupal.comments
;
# Update comments count on wp_posts table.
UPDATE wordpress.wp_posts
SET `comment_count` = (
SELECT COUNT(`comment_post_id`)
FROM wordpress.wp_comments
WHERE wordpress.wp_posts.`id` = wordpress.wp_
comments.`comment_post_id`
)
;

11.You do not have to do anything if you want to keep your
Drupal images and files in the same location, but if you are
FTP-ing your files to the uploads folder in your WordPress
wp-content folder, use the following code to fix the image
URLs.
UPDATE wordpress.wp_posts SET post_content =
REPLACE(post_content, ‚“/files/‘, ‚“/wp-content/
uploads/‘);

12.To fix taxonomy (assuming you’ve set it up correctly in your
original Drupal site), use the following code:
UPDATE IGNORE wordpress.wp_term_relationships,
wordpress.wp_term_taxonomy
SET wordpress.wp_term_relationships.term_taxonomy_id =
wordpress.wp_term_taxonomy.term_taxonomy_id
WHERE wordpress.wp_term_relationships.term_taxonomy_id
= wordpress.wp_term_taxonomy.term_id
;

13.To assign author roles for your users, here’s the code:
INSERT IGNORE INTO wordpress.wp_users
(ID, user_login, user_pass, user_nickname, user_email,
user_registered, user_activation_key, user_status,
display_name)
SELECT DISTINCT
u.uid, u.mail, NULL, u.name, u.mail,
FROM_UNIXTIME(created), ‚' ', 0, u.name
FROM drupal.users u
INNER JOIN drupal.users_roles r
USING (uid)
WHERE (1
# Uncomment and enter any email addresses you want to
exclude below.
# AND u.mail NOT IN (‚test@example.com‘)
)
;

14.Here’s the code you can use to set the author role’s permissions:
INSERT IGNORE INTO wordpress.wp_usermeta (user_id,
meta_key, meta_value)
SELECT DISTINCT
u.uid, 'wp_capabilities',
'a:1:{s:6:“author“;s:1:“1“;}'
FROM drupal.users u
INNER JOIN drupal.users_roles r
USING (uid)
WHERE (1
# Uncomment and enter any email addresses you want to
exclude below.
# AND u.mail NOT IN ('test@example.com')
)
;
INSERT IGNORE INTO wordpress.wp_usermeta (user_id,
meta_key, meta_value)
SELECT DISTINCT
u.uid, 'wp_user_level', '2'
FROM drupal.users u
INNER JOIN drupal.users_roles r
USING (uid)
WHERE (1
# Remove and enter any email addresses you want to
exclude below.
# AND u.mail NOT IN ('test@example.com')
)
;

You can remove the number sign before the line that has
the email address and put your own in so that your remain
the administrator.

15.Use this code to assign and give administrator status:
UPDATE wordpress.wp_usermeta
SET meta_value = 'a:1:{s:13:“administrator“;s:1:“1“;}‘
WHERE user_id IN (1) AND meta_key = 'wp_capabilities' ;
UPDATE wordpress.wp_usermeta
SET meta_value = '10'
WHERE user_id IN (1) AND meta_key = 'wp_user_level'
;

16.This code will help assign authors to the posts they wrote:
UPDATE wordpress.wp_posts
SET post_author = NULL
WHERE post_author NOT IN (SELECT DISTINCT ID FROM
wordpress.wp_users)
;

17. You can then feed the following code for the editor to help
clean it up so that your posts don’t look bizarre after the
conversion.
UPDATE wordpress.wp_posts
SET post_name =
REVERSE(SUBSTRING(REVERSE(post_
name),1,LOCATE('/',REVERSE(post_name))-1)) ;



That’s the basics of migrating your Drupal site to WordPress.

第二个选择:与插件一起使用将Drupal数据库迁移到Wordpress

在本部分中,我们将使用FG Drupal to WordPress plugin进行迁移。该工具非常简单易用,我们将在本文中介绍如何使用它。但是,如果您碰巧遇到任何错误,plugin’s documentation应该会帮助您。

值得注意的是,该插件还提供了高级版本,但免费选项已足够进行常规迁移。但是,如果您希望移动多个作者,您的评论,用户甚至自定义帖子类型,则高级版本可能值得考虑。

步骤1::安装并激活FG Drupal至WordPress插件

步骤2:找出您的Drupal数据库参数

步骤3::将您的Drupal内容导入WordPress

获取更多详细信息,您可以点击链接- How to migrate Drupal to WordPress (in 3 steps)

相关问题