E
E
ElvisP2021-10-05 14:39:55
MySQL
ElvisP, 2021-10-05 14:39:55

How to bulk change image extension to your own format in MYSQL database?

It's hard to explain that's why I'm attaching a screenshot:
615c392974047312328536.jpeg
Images in the database are stored both in .PNG and .WEBP formats.
I want to massively, with 1 request, change all lines where the PNG extension is to the WEBP extension.
How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexalexes, 2021-10-05
@ElvisP

With this request, you study very carefully whether the result of converting strings to result_mod_f1 from mod_f1, and result_mod_f2 from mod_f2 satisfies you.

select mod_f1,  replace(mod_f1, '.png', '.webp') as result_mod_f1,
          mod_f2,  replace(mod_f2, '.png', '.webp') as result_mod_f2
from table

If something does not suit you, rewrite replaces.
If something has been rewritten, then replace the expressions on the right side after the = sign so that the mod_f1 transformation corresponds to mod_f1, and the mod_f2 transformation to mod_f2.
/*update table
set mod_f1 = replace(mod_f1, '.png', '.webp'),
      mod_f2 = replace(mod_f2, '.png', '.webp')*/

You remove the comment, as if you were about to open the protective cover on the red button of the atomic bomb, and fulfill the request.
PS: It is advisable to do this in a software tool that supports an unclosed transaction mode so that it can be rolled back.
PPP: If the table is very large, then it is better to update in portions.
/*update table
set mod_f1 = replace(mod_f1, '.png', '.webp'),
      mod_f2 = replace(mod_f2, '.png', '.webp')
where mod_f1 like '%.png%'
      or mod_f2 like '%.png%'
LIMIT 1000 */

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question