wordpress 数据库_3种在WordPress中备份和还原数据库的方法

本文介绍了WordPress数据库的基础知识以及为何需要备份。通过Udraft Plus插件、phpMyAdmin和MySQL命令行,详细讲解了如何在WordPress中备份和还原数据库。无论你是WordPress新手还是经验丰富的用户,了解这些方法对于保护网站数据至关重要。
摘要由CSDN通过智能技术生成

wordpress 数据库

WordPress is still relevant today, even fifteen years after its first release. It’s often the first choice that comes to one’s mind when starting a new blog.

WordPress至今仍很重要,甚至在其首次发布后十五年。 在开始新博客时,这通常是想到的第一选择。

Although intended to be a content management system, WordPress has been used in a variety of domains in addition to blogging — such as music and ecommerce. As of 2018, WordPress websites account for 14.7% of the top 100 websites.

尽管WordPress旨在用作内容管理系统 ,但除博客之外,它还已用于多种领域,例如音乐和电子商务。 截至2018年,WordPress网站在前100名网站中14.7%

If you manage a WordPress site, WP Admin should mostly be sufficient. However, to protect yourself against situations like corrupted databases or hacks, you should keep backups. As a standard guide, you could go through the advice in the Backing Up Your Database page in the WordPress Codex, which will help you in creating backups of your database.

如果您管理WordPress网站,那么WP Admin通常应该就足够了。 但是,为了保护自己免受数据库损坏或黑客入侵等情况的影响,应保留备份。 作为标准指南,您可以阅读WordPress Codex中“ 备份数据库”页面中的建议,这将帮助您创建数据库备份。

WordPress supports only MySQL and MariaDB as databases, although it’s not impossible to sync other databases like PostgreSQL. This post will assume that you use the default WordPress database option — MySQL — although the steps for MariaDB are very similar. We’ll first cover the basics of the WordPress database, and then move on to backup and restore operations.

WordPress仅支持将MySQL和MariaDB作为数据库,尽管并非不可能同步其他数据库,例如PostgreSQL 。 尽管MariaDB的步骤非常相似,但本文将假定您使用默认的WordPress数据库选项MySQL。 我们将首先介绍WordPress数据库的基础知识,然后继续进行备份和还原操作。

WordPress数据库基础 (WordPress Database Basics)

The WordPress database is provided to you when you’re installing WordPress for the first time. Most webmasters never encounter the database again — as every admin-related action on WordPress is performed through a GUI.

首次安装WordPress时会向您提供WordPress数据库。 大多数网站管理员再也不会遇到数据库了-WordPress上与管理员相关的每项操作都是通过GUI执行的。

WordPress database defined during installationWordPress database defined during installation 安装期间定义的WordPress数据库

If you notice closely, you’re providing WordPress the host of the MySQL server, its username and password to create the required tables. Notice that a prefix is also supplied, which means that all WordPress-related tables would start with the prefix (in case you want to create backups).

如果密切注意,您将向WordPress提供MySQL服务器的主机,其用户名和密码以创建所需的表。 请注意,还提供了前缀,这意味着所有与WordPress相关的表都将以前缀开头(以防您要创建备份)。

WordPress uses the database to broadly store the following data:

WordPress使用该数据库广泛存储以下数据:

  • the settings of your website

    您网站的设置
  • the details of users registered on your website

    在您的网站上注册的用户的详细信息
  • the details of published posts and drafts

    发布的帖子和草稿的详细信息
  • tag information related to your posts

    标记与您的帖子相关的信息
  • comments on your posts (assuming you use the comment system of WordPress and not a third-party comment manager like Disqus).

    对您的帖子进行评论(假设您使用WordPress的评论系统,而不是第三方评论管理器(如Disqus)。

Note: If you’re interested in knowing about details of various tables in the WordPress database and their function, you can refer to this guide on SitePoint.

注意:如果您想了解WordPress数据库中各种表格的详细信息及其功能,可以在SitePoint上参考本指南

Needless to say, keeping a backup of your WordPress directory isn’t sufficient for security purposes. The database needs to be backed up at regular intervals too.

不用说,仅出于安全目的而保留WordPress目录的备份是不够的。 数据库也需要定期备份。

#1 WordPress插件: Udraft Plus (#1 WordPress Plugin: Udraft Plus)

Udraft Plus is a plugin that enables you to back up and restore your entire site, including your database. After installing and activating the plugin, you’re asked to create a backup. Once a backup has been created, you can restore from any backup points in the past.

Udraft Plus是一个插件,使您可以备份和还原整个站点,包括数据库。 安装并激活插件后,系统会要求您创建一个备份。 创建备份后,您可以从过去的任何备份点还原。

Udraft Plus creating a backupUdraft Plus creating a backup Udraft Plus创建备份

In the free tier, you can create backups to a remote location (Dropbox, Drive or Amazon S3), as backing up within the server makes it vulnerable to server failure and attacks. The premium version comes with advanced options like cloning and migration of sites, scheduling backups and reporting.

在免费层中,您可以创建到远程位置(Dropbox,Drive或Amazon S3)的备份,因为服务器内的备份使其容易遭受服务器故障和攻击。 高级版本带有高级选项,例如网站的克隆和迁移,计划备份和报告。

#2 phpMyAdmin (#2 phpMyAdmin)

The next way of managing database dumps through a GUI without the use of any code is through phpMyAdmin.

在不使用任何代码的情况下,通过GUI管理数据库转储的另一种方法是通过phpMyAdmin

If your server management is through a software tool like WAMP or cPanel, PhpMyAdmin comes pre-installed. If your server runs on a Linux-based operating system, phpMyAdmin may even come pre-installed too! In other cases, you can install phpMyAdmin by downloading its source code and configuring it. The installation page has instructions to check which directory phpMyAdmin might be pre-installed in.

如果通过WAMP或cPanel等软件工具进行服务器管理,则将预先安装PhpMyAdmin。 如果您的服务器在基于Linux的操作系统上运行,则phpMyAdmin甚至可能已经预安装! 在其他情况下,您可以通过下载phpMyAdmin的源代码并进行配置来安装它。 安装页面上有说明,以检查phpMyAdmin可能预安装在哪个目录中。

When you have successfully logged into phpMyAdmin, the list of databases is shown on the left column.

成功登录phpMyAdmin后,数据库列表显示在左列。

phpMyAdmin dashboardphpMyAdmin dashboard phpMyAdmin仪表板

Next, select the database which you want to back up. In this case, the WordPress database was named wp. After selecting the database, select the “Export” tab.

接下来,选择要备份的数据库。 在这种情况下,WordPress数据库名为wp 。 选择数据库后,选择“导出”选项卡。

altExport options of phpMyAdmin phpMyAdmin的导出选项

By default, all the tables in the database are exported in the form of SQL queries. You can select a different export option depending on your needs from the drop down list and also select specific tables for the export. However, if your primary reason to export is for backup, make sure you select only from these formats: SQL, CSV or XML. phpMyAdmin also supports three other formats, but you should stick with these three in case you want to transfer it through some other tool. You can import a database by going to the Import tab and uploading the dump file.

默认情况下,数据库中的所有表都以SQL查询的形式导出。 您可以根据需要从下拉列表中选择其他导出选项,还可以选择用于导出的特定表。 但是,如果导出的主要原因是备份,请确保仅从以下格式中选择: SQLCSVXML 。 phpMyAdmin还支持其他三种格式,但是如果要通过其他工具进行传输,则应坚持使用这三种格式。 您可以通过转到“导入”选项卡并上载转储文件来导入数据库。

At this point, it must be mentioned that by default the file size limit is set to 2MB. You’ll have to modify it in your php.ini file and restart the server to work with larger database dumps.

此时,必须指出,默认情况下文件大小限制设置为2MB。 您必须php.ini文件中对其进行修改,然后重新启动服务器以使用较大的数据库转储。

At very large database sizes (say a few gigabytes), it could potentially become difficult to download the database dump through the browser and upload it later. If you’re facing such an issue, you could try the next option.

在非常大的数据库大小(例如几GB)下,可能难以通过浏览器下载数据库转储并在以后上传。 如果您遇到此类问题,可以尝试下一个选项。

MySQL命令行转储 (MySQL Command Line Dumps)

In MySQL, the dump of a database can be downloaded with the mysqldump command:

在MySQL中,可以使用mysqldump命令下载数据库的转储:

mysqldump -u [username] -p[password] [db_name] > backup.sql

In this code:

在此代码中:

  • username is the MySQL username

    用户名是MySQL用户名
  • password is the MySQL password

    password是MySQL密码
  • db_name is the database to be backed up

    db_name是要备份的数据库

  • backup.sql is the name of the file where the backup would be stored.

    backup.sql是将要存储备份的文件的名称。

backup.sql is stored in the same directory where the command is run. Notice in the syntax that there’s a space before [username] but none before [password].

backup.sql存储在运行命令的目录中。 请注意,语法中[username]之前有一个空格,但[password]之前没有一个空格。

If your username is root, password is test and the database to be backed up is wp, the command translates to the following:

如果您的用户名是root ,密码是test并且要备份的数据库是wp ,该命令将转换为以下内容:

mysqldump -u root -ptest wp > backup.sql

In case you want specific tables to be downloaded only, you need to supply the table names after the database:

如果只希望下载特定的表,则需要在数据库后提供表名:

mysqldump -u root -ptest wp wp_posts wp_postmeta > backup.sql

To restore the database, you replace the > with a < in the command:

要还原数据库,请在命令中用<代替>

mysqldump -u [username] -p[password] [db_name] < backup.sql

There’s no modification to restore only specific tables, as the command restores whatever is present your backup.

没有任何修改可仅还原特定的表,因为该命令将还原备份中显示的内容。

最后的想法 (Final Thoughts)

In this post, we looked at the basic functionality of the WordPress database and the importance of backing up your database. Further, we explored three ways of doing this — via a plugin that helps you in backup, via phpMyAdmin, and through the command line.

在本文中,我们研究了WordPress数据库的基本功能以及备份数据库的重要性。 此外,我们探索了三种方法来执行此操作-通过可帮助您进行备份的插件,phpMyAdmin和命令行。

翻译自: https://www.sitepoint.com/back-up-restore-wordpress-databases/

wordpress 数据库

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值