I have a wordpress installation and I've broken the mysql database. For posts the urls are listed as '.../wordpress//...' instead of '.../wordpress/...'
How in SQL can I go through every row in the table and (perhaps use a regular expression) to replace every instance of 'ss//' with 'ss/'?
To replace, use the REPLACE() MySQL function. Since you need to update the table for this, use the UPDATE() function with the SET clause.
MySQL REPLACE() Function The REPLACE() function replaces all occurrences of a substring within a string, with a new substring. Note: This function performs a case-sensitive replacement.
UPDATE sometable SET somefield=REPLACE(somefield,'/wordpress//','/wordpress/');
Edit
@Kevin asked me to explain this query, so here we go:
sometable
assign a new value to somefield
REPLACE()
function does exactly what it says: It replaces text. In our use case we ant it to take the old value of somefield
, then replace all ocurrencies of '/wordpress//' with '/wordpress/'sometable
assign somefield
the value, that results, if you replace all ocurrencies of '/wordpress//' with '/wordpress/' in the old value.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With