Replace part of row in mysql table column

I have a wordpress installation and I broke the mysql database. For posts, URLs are listed as "... / wordpress // ..." instead of "... / wordpress / ... '

How in SQL can I go through every row in the table and (possibly use a regular expression) to replace each instance of 'ss //' with 'ss /'?

+6
source share
1 answer
UPDATE sometable SET somefield=REPLACE(somefield,'/wordpress//','/wordpress/'); 

Edit

@ Kevin asked me to explain this question, so we go:

  • I assume the basic UPDATE is clear: on all sometable lines sometable assign a new value to somefield
  • The REPLACE() function does exactly what it says: it replaces the text. In our case, we ant will take the old value of somefield , then replace all the values โ€‹โ€‹"/ wordpress //" with "/ wordpress /"
  • these two parts, taken together, mean that in all sometable lines sometable set somefield value you get if you replace all the values โ€‹โ€‹of "/ wordpress //" with "/ wordpress /" in the old value.
+15
source

Source: https://habr.com/ru/post/956676/


All Articles