Delete file using MySQL procedure

Is there a way to delete a file using the SQL command?
I have image files in the file system and links to them in the database. For instance:

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;  

When the category \ product is deleted, links to images belonging to the deleted category \ product are deleted. ("DELETE CASCADE")
But I also need to delete the files. Sort of:

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

Of course, it is possible to create a table of all the files that need to be deleted. I ask if there is a way to do this in real time.
Thanks

+1
source share
1 answer

MySQL. , , , - , SELECT ... INTO OUTFILE .... , .

+2

All Articles