Find and Replace Values in Database in MySQL?

By Moe Jame Share
Browse the MySQL category for more tutorials

How to Find and Replace values in a database with MySQL?

1. Connect to your Database using the application of your choice. We will be using PHPMyAdmin for this tutorial.

Select your Table where you want to find and replace value in. In this example, we want to find and replace links that are not working properly in a table named wp_blc_links.

Select the table in which you would like to run a "Find and Replace" query

2. IMPORTANT: Backup the database and tables in question to avoid any loss of data!

3. Write down the name of the column in the table you would like to replace data in.

Select the right Table

4. In this example, the name of the column is url.

Write down the name of the column you would like to replace data in

5. Go ahead and click on SQL on the top

click on SQL

6. And type in the following SQL Query. Again MAKE SURE YOU HAVE A BACKUP OF YOUR DATABASE FIRST.

Our goal here was to replace within the tale named wp_blc_links and only in the column url any value that is equal to https://thinktutorial.com/smartphones/iphone/wp-content/uploads/ with https://thinktutorial.com/wp-content/uploads/

UPDATE table_name set column_name = replace(column_name, ‘replace this’, ‘with that’);

Copy/Paste it from here and modify it to fit your needs. Only replace the value in between [ … ]

UPDATE [table] set [columnname] = replace([columnname], ‘[replace this]’, ‘[with that]’);

7. Press “Go” to run the QUERY.

Press Go to run the SQL Query

8. You are done!

SQL query "find and replace" did go through successfully

 

Keywords

ColumnFindFind And ReplaceQueryReplace

More MySQL Tutorials

How to Find and Replace Values in Database on MySQL

Follow us on Twitter Subscribe to our Feeds Become a Fan on Facebook

Follow Us

RSS
facebook
twitter

Didn't find your answer?

Post your question on our forum and ask the community!

Ask a question!