Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UPDATE `table_name`
- SET `field_name` = replace(same_field_name, 'unwanted_text', 'wanted_text')
- // Connect to your MySQL database.
- $hostname = "localhost";
- $username = "db_username";
- $password = "db_password";
- $database = "db_name";
- mysql_connect($hostname, $username, $password);
- // The find and replace strings.
- $find = "find_this_text";
- $replace = "replace_with_this_text";
- $loop = mysql_query("
- SELECT
- concat('UPDATE ',table_schema,'.',table_name, ' SET ',column_name, '=replace(',column_name,', ''{$find}'', ''{$replace}'');') AS s
- FROM
- information_schema.columns
- WHERE
- table_schema = '{$database}'")
- or die ('Cant loop through dbfields: ' . mysql_error());
- while ($query = mysql_fetch_assoc($loop))
- {
- mysql_query($query['s']);
- }
- mysqldump -u user -p databasename > ./db.sql
- sed -i 's/oldString/newString/g' ./db.sql
- mysql -u user -p databasename < ./db.sql
- UPDATE `tj_posts`
- SET `post_content` = replace(post_content, 'mysite.com/wordpress', 'mysite.com/news')
- UPDATE table SET field = replace(field, text_needs_to_be_replaced, text_required);
- UPDATE student SET student_name = replace(student_name, 'John', 'Mark');
- SELECT CONCAT(
- 'update ', table_name ,
- ' set ', column_name, ' = replace(', column_name,', ''www.oldDomain.com'', ''www.newDomain.com'');'
- ) AS statement
- FROM information_schema.columns
- WHERE table_schema = 'mySchema' AND table_name LIKE 'yourPrefix_%';
- UPDATE `wp_posts` AS `toUpdate`,
- (SELECT `ID`,REPLACE(`guid`,'http://old.tld','http://new.tld') AS `guid`
- FROM `wp_posts` WHERE `guid` LIKE 'http://old.tld%') AS `updated`
- SET `toUpdate`.`guid`=`updated`.`guid`
- WHERE `toUpdate`.`ID`=`updated`.`ID`;
- SELECT `toUpdate`.`guid` AS `old guid`,`updated`.`guid` AS `new guid`
- FROM `wp_posts` AS `toUpdate`,
- (SELECT `ID`,REPLACE(`guid`,'http://old.tld','http://new.tld') AS `guid`
- FROM `wp_posts` WHERE `guid` LIKE 'http://old.tld%') AS `updated`
- WHERE `toUpdate`.`ID`=`updated`.`ID`;
Add Comment
Please, Sign In to add comment