Mysql – 9000 rows affected message, but no rows actually changed

MySQLphpmyadmin

I'm having a problem with MySQL. When I run the code below, via phpmyadmin:

UPDATE wp_posts 
    SET post_content = REPLACE
        (
        post_content,
        '31.media.tumblr.com/',
        '41.media.tumblr.com/'
        ) 
    WHERE post_content LIKE '%31.media.tumblr.com/%' 
    AND post_content NOT LIKE '%.gif%';

It returns:

9000 rows affected

If I make a search, it shows that it replaced all the needed things successfully. But if I go and hit the 'EDIT' option in phpmyadmin on one of the rows inside the post_content column, no changes are done inside it; everything stays the same.

What might be the reason?

For me there's something wrong with the code above. Maybe it returns NULL or something and stops the update. If I remove this part:

AND post_content NOT LIKE '%.gif%';

…it does work properly.

The database is a default WordPress one:

Screenshot 1

Screenshot 2

Example of data inside post_content:

<p>some text</p>
<img src="http://31.media.tumblr.com/eet1r5co8so1/tumblr_mzlt6zqeet1r5co8so1.gif" alt="" />
<img src="http://11.media.tumblr.com/L4B1q/tumblr_ml5i2cGL4B1qz4fjqo1.gif" alt="" />
other text
<img src="http://51.media.tumblr.com/n42sryL4JG1rda3bfo1/tumblr_n42sryL4JG1rda3bfo1.jpg" alt="" />
<img src="http://31.media.tumblr.com/eet1r5co8so1/tumblr_noui3gHzxp1qfvouao1_1280.jpg" alt="" />
some other text
...

Best Answer

I did the same as you did and it worked.

mysql> INSERT INTO `test`.`wp_posts` (`idws_posts`, `post_content`) VALUES ('1', '<img src="http://31.media.tumblr.com/eet1r5co8so1/tumblr_mzlt6zqeet1r5co8so1.gif" alt="" />');
Query OK, 1 row affected (0.01 sec)

mysql> INSERT INTO `test`.`wp_posts` (`idws_posts`, `post_content`) VALUES ('2', '<img src="http://11.media.tumblr.com/L4B1q/tumblr_ml5i2cGL4B1qz4fjqo1.gif" alt="" />');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO `test`.`wp_posts` (`idws_posts`, `post_content`) VALUES ('3', '<img src="http://51.media.tumblr.com/n42sryL4JG1rda3bfo1/tumblr_n42sryL4JG1rda3bfo1.jpg" alt="" />');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO `test`.`wp_posts` (`idws_posts`, `post_content`) VALUES ('4', '<img src="http://31.media.tumblr.com/eet1r5co8so1/tumblr_noui3gHzxp1qfvouao1_1280.jpg" alt="" />');
Query OK, 1 row affected (0.00 sec)

mysql> 
mysql> SELECT * FROM test.wp_posts;
+------------+----------------------------------------------------------------------------------------------------+
| idws_posts | post_content                                                                                       |
+------------+----------------------------------------------------------------------------------------------------+
|          1 | <img src="http://31.media.tumblr.com/eet1r5co8so1/tumblr_mzlt6zqeet1r5co8so1.gif" alt="" />        |
|          2 | <img src="http://11.media.tumblr.com/L4B1q/tumblr_ml5i2cGL4B1qz4fjqo1.gif" alt="" />               |
|          3 | <img src="http://51.media.tumblr.com/n42sryL4JG1rda3bfo1/tumblr_n42sryL4JG1rda3bfo1.jpg" alt="" /> |
|          4 | <img src="http://31.media.tumblr.com/eet1r5co8so1/tumblr_noui3gHzxp1qfvouao1_1280.jpg" alt="" />   |
+------------+----------------------------------------------------------------------------------------------------+
4 rows in set (0.00 sec)

mysql> 
mysql> UPDATE test.wp_posts 
    ->     SET post_content = REPLACE(post_content,'31.media.tumblr.com/','41.media.tumblr.com/') 
    ->     WHERE post_content LIKE '%31.media.tumblr.com/%' AND post_content NOT LIKE '%.gif%';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql>         
mysql> SELECT * FROM test.wp_posts;
+------------+----------------------------------------------------------------------------------------------------+
| idws_posts | post_content                                                                                       |
+------------+----------------------------------------------------------------------------------------------------+
|          1 | <img src="http://31.media.tumblr.com/eet1r5co8so1/tumblr_mzlt6zqeet1r5co8so1.gif" alt="" />        |
|          2 | <img src="http://11.media.tumblr.com/L4B1q/tumblr_ml5i2cGL4B1qz4fjqo1.gif" alt="" />               |
|          3 | <img src="http://51.media.tumblr.com/n42sryL4JG1rda3bfo1/tumblr_n42sryL4JG1rda3bfo1.jpg" alt="" /> |
|          4 | <img src="http://41.media.tumblr.com/eet1r5co8so1/tumblr_noui3gHzxp1qfvouao1_1280.jpg" alt="" />   |
+------------+----------------------------------------------------------------------------------------------------+
4 rows in set (0.00 sec)

mysql> 

Are not you missing something?