skip to Main Content

I have some link broken on my site and I need to change a lot of links. My initial idea was to go through MySQL and replace strings like <a href="/old-link/"> with <a href="/new-link/">.

When I go to Database – Search and enter Search for: <a href="/old-link/">, select all tables and choose Exact Match, nothing is found. If I choose Any word instead of Exact match, it founds many irrelevant results.

I want to search for exact match for string <a href="/old-link/"> in order to ensure that i don’t replace something that mustn’t be replaced.

I suspect that nothing is found because many special symbols like <>""// are used in my search, but I can’t google any coherent info as to how to put the query correctly. Can somebody help me with this?

P.S. I’ve also run through topics that were suggested by stackoverflow during creation of this question, but didn’t find an answer

P.P.S I updated post with "code" markup as I didn’t know it had to be done beforehand

2

Answers


  1. Just use the sql replace function

    UPDATE yourTable SET yourColumn = REPLACE(yourColumn, 'href="/old-link/"', 'href="/new-link/");
    

    Solution Provided by @PunitGajjar

    Login or Signup to reply.
  2. As I explained in the comment, you can go with some loops like below.
    This is an example with a PHP script.
    You can use the same kind of logic with the whatever technologies you are using.

    Suggesting you to create an array just because there are chances that you may not have same column name in all the tables you wish to update.

    $myArray = [
        "table_one" => "table_one_column",
        "table_two" => "table_two_column",
        "table_three" => "table_three_column",
        "table_four" => "table_four_column"
    ];
    
    foreach ($myArray as $tableName => $columName){
        /* Your query execution */
        $query = "UPDATE ".$tableName." SET ".$columName." = REPLACE(".$columName.", 'href="/old-link/"', 'href="/new-link/");";
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search