I'd like to check logs and store to a file using trigger and don't want to create a log table. (the code column is updated to null sometimes but can not find what causes the problem) Some articles said that the using SELECT, can output to a file but, trigger doesn't be created with the following code and I am not sure I did understand the trigger well.
// before updating
CREATE TRIGGER pre_code BEFORE UPDATE ON customer
FOR EACH ROW
BEGIN
IF NEW.code IS NULL THEN
SELECT id, name, code, updated_at INTO OUTFILE '/logs/codes.txt'
LINES TERMINATED BY '\n'
FROM customer WHERE id = OLD.id;
END IF;
END;
// after updating
CREATE TRIGGER post_code AFTER UPDATE ON customer
FOR EACH ROW
BEGIN
IF NEW.code IS NULL THEN
SELECT id, name, code, updated_at INTO OUTFILE '/logs/codes.txt'
LINES TERMINATED BY '\n'
FROM customer WHERE id = OLD.id;
END IF;
END;
Thank you in advance.