简体   繁体   English

将 Blob 列从 mysql dB 导出到磁盘并用新文件名替换

[英]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.在少于 10000 条记录的表中,简单的 select 查询最多可能需要 10 秒。

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.除了添加适当的索引外,我还能够运行与过去需要 10-15 秒才能在 1 秒内运行的完全相同的查询。

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?是否有任何现有的工具或脚本可以用来帮助我从数据库中导出这些 blob(视频)并将其保存到磁盘并使用文件系统上的新文件名/路径更新行?

If not is there any proper way to optimize database so that those blob would not impact performance that much?如果没有,是否有任何适当的方法来优化数据库,以便这些 blob 不会对性能产生太大影响?

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.提示使用此数据库的某些客户端使用高级 orms,因此我们对 orm 用于获取行及其关系的查询没有太多控制。 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这些也是INTO_OUTFILE而不是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: 13.2.10.1 SELECT... INTO 语句 SELECT... INTO 形式的 SELECT 可以将查询结果存储在变量中或写入文件:

SELECT... INTO var_list selects column values and stores them into variables. SELECT... INTO var_list 选择列值并将它们存储到变量中。

SELECT... INTO OUTFILE writes the selected rows to a file. SELECT... INTO OUTFILE 将选定的行写入文件。 Column and line terminators can be specified to produce a specific output format.可以指定列和行终止符以生成特定的 output 格式。

SELECT... INTO DUMPFILE writes a single row to a file without any formatting. SELECT... INTO DUMPFILE 在没有任何格式的情况下将单行写入文件。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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