简体   繁体   中英

Export blob column from mysql dB to disk and replace it with new file name

So I'm working on a legacy database, and unfortunately the performance of database is very slow. Simple select query can take up to 10 seconds in tables with less than 10000 record.

So i tried to investigate problem and found out that deleting column that they have used to store files (mostly videos and images) fix the problem and improve performance a lot.

Along with adding proper indexes I was able to run exact same query that used to take 10-15sec to run in under 1sec.

So my question is. Is there any already existing tool or script I can use to help me export those blobs (videos) from database and save the to disk and update row with new file name/path on file system?

If not is there any proper way to optimize database so that those blob would not impact performance that much?

Hint some one clients consuming this database use high level orms so we don't have much control on queries orm use to fetch rows and its relations. So I cannot optimize queries directly.

SELECT column FROM table1 WHERE id = 1 INTO DUMPFILE 'name.png';

How about this way?

These is also INTO_OUTFILE instead of INTO_DUMPFILE

13.2.10.1 SELECT... INTO Statement The SELECT... INTO form of SELECT enables a query result to be stored in variables or written to a file:

SELECT... INTO var_list selects column values and stores them into variables.

SELECT... INTO OUTFILE writes the selected rows to a file. Column and line terminators can be specified to produce a specific output format.

SELECT... INTO DUMPFILE writes a single row to a file without any formatting.

Link: https://dev.mysql.com/doc/refman/8.0/en/select-into.html

Link: https://dev.mysql.com/doc/refman/8.0/en/select.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM