InMotion Hosting Support Center

sql update replace

Category: Databases

2013-03-20 2:05 am EST

Hits: 424
I need to replace all instances of http://oldwebsite with http://newwebsite with out removing other content in Column.

Where can I get me some cookies?&nbsp; <img alt="surprise" height="20" src="http://oldwebsite/plugin/wysiwyg-editor/plugins/smiley/images/omg_smile.gif" title="surprise" width="20"></p>

Need it to be changed to.

Where can I get me some cookies?&nbsp; <img alt="surprise" height="20" src="http://newwebsite/plugin/wysiwyg-editor/plugins/smiley/images/omg_smile.gif" title="surprise" width="20"></p>

Will the update replace do this without removing every thing else.

UPDATE posts SET content = replace(content, 'http://oldwebsite/da/', 'http://newwebsite/da/' ) ;

You must login before you can ask a follow up question.

You must login before you can submit an answer.



5,399 Points
2013-03-20 2:13 am EST
Hi False007,

The syntax for you Update query looks correct at first look. As long as the information you want to change is in the posts table and specifically in the content column, you should be OK.

To be on the safe side however, but sure to <a href=''>generate a backup of your database</a> before running a command like this.

I hope that helps! Let us know if we can help any further.

- Brad

You must login before you can post a comment about this answer.

Thank you for the quick answer Brad.
22 Points
2013-03-20 2:43 am EST

5,889 Points
2013-03-20 2:18 am EST
Thank you for your question False007!

You can run an SQL statement; however, this will change your live database. If the SQL statement goes wrong for any reason, your live copy can be damaged.

You can <a href="">export your database</a> as an SQL file to your local computer. Make a copy of it, then use find and replace in a text editor like Notepad++ to find and replace all instances of the old domain with the new domain. After you get the backup copy updated you can <a href="">Import the database on your server</a>. This way you can prevent any problems that may arise when changing the URL and keep a back up of the database.

Best Regards,
James R

You must login before you can post a comment about this answer.

Makes good sence, not run a SQL statement on a live database. Thank you for the wize advice.
22 Points
2013-03-20 2:47 am EST
Like this Question?

Support Center Login

Our Login page has moved, Click the button below to be taken to the login page.

Need more Help?


Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail:
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!