使用MySQL程序删除文件 [英] delete file using MySQL procedure

查看:111
本文介绍了使用MySQL程序删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用SQL命令删除文件?
我在文件系统中有图像文件,并在DB中链接到它们.例如:

Is there any way to delete file using SQL command ?
I have image files in filesystem, and links to them in DB. For example:

CREATE TABLE products (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    name TINYTEXT NOT NULL,
    category INT UNSIGNED NOT NULL,
    FOREIGN KEY (category) REFERENCES categories(id) ON DELETE CASCADE,
    ............
) ENGINE=InnoDB;
CREATE TABLE images (
    id INT UNSIGNED NOT NULL AUTO_INCREMENT,
    img_link TINYTEXT, /*path and name of JPG/PNG file*/
    product INT UNSIGNED NOT NULL,
    FOREIGN KEY (product) REFERENCES products(id) ON DELETE CASCADE,
    ............
) ENGINE=InnoDB;  

删除类别\产品后,将删除属于已删除的类别\产品的图像的链接. (因为'ON DELETE CASCADE')
但是我也需要删除文件本身.像这样:

When category\product deleted, deletes the links of images that belong to the deleted category\product. (becouse 'ON DELETE CASCADE')
But I need to delete the files itself too. Something like:

CREATE TRIGGER del BEFORE DELETE ON images FOR EACH ROW CALL delete_file(OLD.img_link);

当然可以创建必须删除的所有文件的表.我问是否有任何实时方法.
谢谢

Of course its possible to create table of all files that must be deleted. I ask if is there any way to do it at real-time.
Thanks

推荐答案

您不能在MySQL内部执行此操作.它唯一可以影响文件的就是在SELECT ... INTO OUTFILE ...查询中创建新文件.没有处理外部文件的功能,更不用说删除它们了.

You can't do this from within MySQL. The only things it can do to affect files are create new ones as part of a SELECT ... INTO OUTFILE ... query. There's no facilities for manipulating external files, let alone deleting them.

这篇关于使用MySQL程序删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆