迁移WordPress数据库简介:基础数据库知识

Wordpress8个月前发布 SUYEONE
1.1K 0 0

When dealing with WordPress-based projects, one of the most frustrating or tedious aspects is synchronizing Databases across environments. Of course, using test data in development, user data in staging, and real data in production makes sense, but there’s no one-size-fits-all solution, right? This means that test data can work sometimes, but not always. For instance, imagine inheriting a project and needing to extract its database to work with existing data. Or, suppose you have to migrate an entire Website or application from one server to another. In such cases, test data isn’t much help. Instead, you need a tool.

The WordPress Importer is a decent basic migration tool, and if you’re comfortable with a database frontend or SQL itself, running SQL exports and imports works well. But what about those in between? The fact that migrations are easy can be a mixed blessing when it comes to WordPress database migration, as many of us have varying skill levels depending on our preferred stack components.

前端工作更熟悉的 folks might not be well-versed in the application layer and/or the database layer. Those accustomed to the application layer may also excel in front-end work but not in databases (and vice versa). Those who live in databases might feel uncomfortable with the upper layers. This doesn’t mean there aren’t full-stack developers; there certAInly are, but not everyone finds themselves in that position.

As a result, some people face more challenges than others when migrating WordPress databases. Or, while familiar with SQL, some might just be looking for a tool to simplify the entire process.

In this Series. we’ll explore a utility that can achieve this goal, but before that, let’s quickly review the WordPress database to ensure we’re on the same page.

**WordPress Database**

When discussing the WordPress database, entire articles could be written about each table, column, architecture, best query practices, and so on. This isn’t that series. Instead, we’ll do two things in this article:

1. Ensure we all have a clear conceptual understanding of the database, so we can describe it mentally.
2. Examine each table in the WordPress database to understand the types of data stored in them. Ultimately, this should help those who spend more time on the front-end comprehend some underlying workings and might assist those who spend more time in the application layer using the WordPress API to know which functions correspond to which tables, leading to better code.

**What is a Database?**

Most Wptuts+ readers likely have a general idea of what a database is. Here’s a direct quote from Wikipedia:

While this is a fair definition, I don’t think it adequately describes the WordPress database or similar web applications—it’s a bit too broad. So, let’s create a working definition for the rest of this series.

One confusing aspect in the shared explanation might be the interrelation of tables. We’ll revisit this idea before we conclude the article, but first, let’s discuss the WordPress database.

**WordPress Database Architecture**

In short, a WordPress database consists of 11 tables (unless you use Multisite, which is beyond the scope of this series). Each table has its own set of columns representing various information stored within. For example, the wp_posts table has a column called post_content, which stores the actual content of a post.

Here’s a brief overview of the tables:

1. wp_users contains a list of users registered to a WordPress installation, including email addresses, passwords, display names, etc.
2. wp_usermeta holds adDiTional information related to each user. Extra user details can be stored here.
3. wp_posts is where all post information is stored. Everything like titles, content, etc., for posts, pages, and custom post types is kept here.
4. wp_postmeta stores metadata for each post, allowing you to save and retrieve more information about a post.
5. wp_comments is where comments for each post (regardless of type) are stored.
6. wp_commentmeta, like other “meta” tables, lets you store more information about each comment.
7. wp_terms is where categories and tags are stored. Since relationships between posts, pages, custom post types, categories, and tags can become complex, additional tables are needed.
8. wp_{$TERM}_taxonomy provides descriptions for categories or tags (even links, if you still use them) in the wp_terms table.
9. wp_{$TERM}_relationships store the relationship between a given post and its categories and/or tags.
10. wp_options is where all settings are saved, including those configured through WordPress and those created via the Settings API.
11. wp_links is a table that still exists in the WordPress database, though there’s no UI option for data. If you’ve ever used this feature, you’re familiar with how links work; this is where they’re stored.

That’s it for the WordPress database. Relatively simple, right? Posts are saved in the posts table, comments in the comments table, users in the users table, and so on. Of course, there are nuances (like pages being stored in the Posts table), but it’s a relatively straightforward Model.

This simplicity is a good thing. Remember when we mentioned that some tables can reference each other? Comments and posts are a perfect example. Because comments are left on specific posts, comments need to know which post ID they’re associated with, so when loading a post, the comments related to that post ID can be retrieved.

Anyway, that’s more than we’ll delve into in this series, but I hope this gives you a good idea. If you’re interested in more technical details or the relationships between tables and columns, be sure to check out the WordPress Codex article on the database description.

**Conclusion**

We’ve covered everything necessary for an introduction to the WordPress database. Hopefully, this sheds light on what happens behind the scenes when you save information in WordPress. Now that we’ve introduced the organization, it’s time to look at a tool that can make data migration incredibly simple.

Knowing how the database is structured, we should also understand how migrations work. Stay tuned for more insights in the upcoming articles!

© 版权声明

相关文章

暂无评论

暂无评论...
☺一键登录开启个人书签等功能!