Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. UPDATE `table_name`
  2. SET `field_name` = replace(same_field_name, 'unwanted_text', 'wanted_text')
  3.  
  4. UPDATE `tj_posts`
  5. SET `post_content` = replace(post_content, 'mysite.com/wordpress', 'mysite.com/news')
  6.  
  7. // Connect to your MySQL database.
  8. $hostname = "localhost";
  9. $username = "db_username";
  10. $password = "db_password";
  11. $database = "db_name";
  12.  
  13. mysql_connect($hostname, $username, $password);
  14.  
  15. // The find and replace strings.
  16. $find = "find_this_text";
  17. $replace = "replace_with_this_text";
  18.  
  19. $loop = mysql_query("
  20. SELECT
  21. concat('UPDATE ',table_schema,'.',table_name, ' SET ',column_name, '=replace(',column_name,', ''{$find}'', ''{$replace}'');') AS s
  22. FROM
  23. information_schema.columns
  24. WHERE
  25. table_schema = '{$database}'")
  26. or die ('Cant loop through dbfields: ' . mysql_error());
  27.  
  28. while ($query = mysql_fetch_assoc($loop))
  29. {
  30. mysql_query($query['s']);
  31. }
  32.  
  33. mysqldump -u user -p databasename > ./db.sql
  34.  
  35. sed -i 's/oldString/newString/g' ./db.sql
  36.  
  37. mysql -u user -p databasename < ./db.sql
  38.  
  39. UPDATE table SET field = replace(field, text_needs_to_be_replaced, text_required);
  40.  
  41. UPDATE student SET student_name = replace(student_name, 'John', 'Mark');
  42.  
  43. UPDATE `wp_posts` AS `toUpdate`,
  44. (SELECT `ID`,REPLACE(`guid`,'http://old.tld','http://new.tld') AS `guid`
  45. FROM `wp_posts` WHERE `guid` LIKE 'http://old.tld%') AS `updated`
  46. SET `toUpdate`.`guid`=`updated`.`guid`
  47. WHERE `toUpdate`.`ID`=`updated`.`ID`;
  48.  
  49. SELECT `toUpdate`.`guid` AS `old guid`,`updated`.`guid` AS `new guid`
  50. FROM `wp_posts` AS `toUpdate`,
  51. (SELECT `ID`,REPLACE(`guid`,'http://old.tld','http://new.tld') AS `guid`
  52. FROM `wp_posts` WHERE `guid` LIKE 'http://old.tld%') AS `updated`
  53. WHERE `toUpdate`.`ID`=`updated`.`ID`;
  54.  
  55. update TABLE_NAME set FIELD_NAME =
  56. replace(FIELD_NAME, 'Text to find', 'text to replace with');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement