Guest User

Untitled

a guest
Nov 3rd, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. UPDATE `table_name`
  2. SET `field_name` = replace(same_field_name, 'unwanted_text', 'wanted_text')
  3.  
  4. // Connect to your MySQL database.
  5. $hostname = "localhost";
  6. $username = "db_username";
  7. $password = "db_password";
  8. $database = "db_name";
  9.  
  10. mysql_connect($hostname, $username, $password);
  11.  
  12. // The find and replace strings.
  13. $find = "find_this_text";
  14. $replace = "replace_with_this_text";
  15.  
  16. $loop = mysql_query("
  17. SELECT
  18. concat('UPDATE ',table_schema,'.',table_name, ' SET ',column_name, '=replace(',column_name,', ''{$find}'', ''{$replace}'');') AS s
  19. FROM
  20. information_schema.columns
  21. WHERE
  22. table_schema = '{$database}'")
  23. or die ('Cant loop through dbfields: ' . mysql_error());
  24.  
  25. while ($query = mysql_fetch_assoc($loop))
  26. {
  27. mysql_query($query['s']);
  28. }
  29.  
  30. mysqldump -u user -p databasename > ./db.sql
  31.  
  32. sed -i 's/oldString/newString/g' ./db.sql
  33.  
  34. mysql -u user -p databasename < ./db.sql
  35.  
  36. UPDATE `tj_posts`
  37. SET `post_content` = replace(post_content, 'mysite.com/wordpress', 'mysite.com/news')
  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. SELECT CONCAT(
  44. 'update ', table_name ,
  45. ' set ', column_name, ' = replace(', column_name,', ''www.oldDomain.com'', ''www.newDomain.com'');'
  46. ) AS statement
  47. FROM information_schema.columns
  48. WHERE table_schema = 'mySchema' AND table_name LIKE 'yourPrefix_%';
  49.  
  50. UPDATE `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. SET `toUpdate`.`guid`=`updated`.`guid`
  54. WHERE `toUpdate`.`ID`=`updated`.`ID`;
  55.  
  56. SELECT `toUpdate`.`guid` AS `old guid`,`updated`.`guid` AS `new guid`
  57. FROM `wp_posts` AS `toUpdate`,
  58. (SELECT `ID`,REPLACE(`guid`,'http://old.tld','http://new.tld') AS `guid`
  59. FROM `wp_posts` WHERE `guid` LIKE 'http://old.tld%') AS `updated`
  60. WHERE `toUpdate`.`ID`=`updated`.`ID`;
Add Comment
Please, Sign In to add comment