![](https://i-blog.csdnimg.cn/blog_migrate/0cb84df2330a721452e1afbc603fccb1.png)
wordpress 数据库
Are you looking to do a mass search and replace in WordPress? Whether you want to find and replace a specific text, URL, or an image, you can easily do so by using a find and replace WordPress plugin or a simple SQL query. In this article, we will show you how to find and replace text in your WordPress database.
您是否要在WordPress中进行大量搜索并替换? 无论您要查找并替换特定的文本,URL还是图像,都可以使用查找并替换WordPress插件或简单SQL查询轻松地做到这一点。 在本文中,我们将向您展示如何在WordPress数据库中查找和替换文本。
![Find and replace text in WordPress database with just one click Find and replace text in WordPress database with just one click](https://i-blog.csdnimg.cn/blog_migrate/51634c030bfdcc8dce03133a79226ec4.png)
什么时候需要查找和替换WordPress数据库? (When You May Need Find & Replace for WordPress Database?)
Let’s suppose that you have added specific text or URL to a number of your posts. You don’t know which posts you have added that text to, but you do know that there are a lot of them.
假设您已经在许多帖子中添加了特定的文本或URL。 您不知道将这些文本添加到了哪些帖子中,但是您确实知道有很多帖子。
Now you can manually search your site and edit every single post one by one. That’s going to take time and has a high chance of you missing some occurrences.
现在,您可以手动搜索您的站点并逐一编辑每个帖子。 这将需要时间,并且很有可能错过某些事件。
Using a single command to automatically find and replace will do the same thing but much quicker and efficiently.
使用单个命令自动查找和替换将执行相同的操作,但是更加快捷有效。
There is one downside to it though. If you made a mistake, then you will not be able to undo it. Once you replace the text, it is gone. You will need to carefully type the text you are looking for and the text you want to replace it with.
但是它有一个缺点。 如果您输入有误,将无法撤消。 替换文本后,它就消失了。 您将需要仔细键入要查找的文本以及您要替换为的文本。
Having said that, let’s see how you can easily find and replace text in your WordPress database.
话虽如此,让我们看看如何轻松地在WordPress数据库中查找和替换文本。
入门 (Getting Started)
As we mentioned earlier that the changes you make to your database will not be reversible. You need to take every precaution to make sure that you don’t lose data.
如前所述,您对数据库所做的更改将是不可逆的。 您需要采取一切预防措施,以确保不会丢失数据。
First you need to create a WordPress database backup. You can do that by using a WordPress backup plugin. Alternatively, you can also create a database backup using phpMyAdmin.
首先,您需要创建一个WordPress数据库备份。 您可以使用WordPress备份插件来做到这一点。 另外,您也可以使用phpMyAdmin创建数据库备份 。
After creating the backup of your WordPress database, you can move on to run your find and replace commands.
创建WordPress数据库的备份后,您可以继续运行查找和替换命令。
运行查找并替换为WordPress插件 (Running Find and Replace with a WordPress plugin)
If you are not familiar with code and don’t want to write a custom SQL query, then there is an easy to use find and replace WordPress plugin called Better Search Replace.
如果您不熟悉代码并且不想编写自定义SQL查询,那么有一个易于使用的查找和替换WordPress插件,称为Better Search Replace 。
![Better search replace plugin settings Better search replace plugin settings](https://i-blog.csdnimg.cn/blog_migrate/c2966d04a2b54e560ce8afd4251ec104.png)
It allows you to run search and replace commands from inside your WordPress admin area. We have a detailed guide on how to search and replace in WordPress with Better Search Replace plugin.
它允许您从WordPress管理区域内运行搜索和替换命令。 我们有一个详细的指南, 介绍如何使用Better Search Replace插件在WordPress中进行搜索和替换 。
使用phpMyAdmin运行查找和替换MySQL查询 (Running Find & Replace MySQL Query with phpMyAdmin)
You can also use phpMyAdmin to find and replace text from your WordPress database.
您还可以使用phpMyAdmin从WordPress数据库中查找和替换文本。
First you need to login to cPanel dashboard of your WordPress hosting. Scroll down to the database section and then click on phpMyAdmin.
首先,您需要登录到WordPress托管的 cPanel仪表板。 向下滚动到数据库部分,然后单击phpMyAdmin。
![phpMyAdmin phpMyAdmin](https://i-blog.csdnimg.cn/blog_migrate/400a57c8dd8173330a9ac0bb8ab85809.png)
The screenshot above is showing the cPanel dashboard on BlueHost. Your cPanel dashboard may look slightly different.
上面的屏幕截图显示了BlueHost上的cPanel仪表板。 您的cPanel仪表板可能看起来略有不同。
This will launch phpMyAdmin where you will need to click on your WordPress database name and then click on SQL.
这将启动phpMyAdmin,您需要在其中单击WordPress数据库名称,然后单击SQL。
![Running SQL query in phpMyAdmin Running SQL query in phpMyAdmin](https://i-blog.csdnimg.cn/blog_migrate/e13a8ec53df050f3f4a630c5913c6cf7.png)
You will need to enter your SQL query in this format:
您将需要使用以下格式输入您SQL查询:
update TABLE_NAME set FIELD_NAME =
replace(FIELD_NAME, 'Text to find', 'text to replace with');
For example, if you wanted to search for text in a WordPress post’s content, then you would write your query like this:
例如,如果您要搜索WordPress帖子内容中的文本,则可以这样编写查询:
update wp_posts set post_content =
replace(post_content,'Text to find','text to replace with');
Click on the ‘Go’ button to continue.
点击“开始”按钮继续。
PhpMyAdmin will run your SQL query and upon success it will show the number of rows affected by the query.
PhpMyAdmin将运行您SQL查询,成功后将显示该查询影响的行数。
You can now visit your WordPress site to see your changes in action.
现在,您可以访问WordPress网站以查看您所做的更改。
We hope this article helped you learn how to find and replace text with one click in your WordPress database. You may also want to see our beginner’s guide on WordPress database management with phpMyAdmin.
我们希望本文能帮助您学习如何在WordPress数据库中一键式查找和替换文本。 您可能还希望查看有关使用phpMyAdmin进行WordPress数据库管理的初学者指南。
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在Twitter和Facebook上找到我们。
wordpress 数据库