[syslog-ng] Running ON INSERT UPDATE (MySQL)

Bill Nash billn at odyssey.billn.net
Fri Mar 17 17:40:53 CET 2006



I may be wrong, not having tried what you're attempting, but I don't 
think the syntax you're attempting is valid. Mysql 5.1 documentation 
agrees with me.

But! I think you're thinking of a trigger.

create tigger NumRowUpdate after insert on logs
for each row begin
 	update NumRows set NumRowsLogs=NumRowsLogs+1
end

This would add the logic to your logs table to direct mysql to update that 
counter every time a row is inserted. You may or may not want to pair it 
with a delete equivalant to maintain that counter, depending on your 
requirements.

(Note: I just pulled that statement out of my shorts, please check for 
syntax.)

- billn

On Fri, 17 Mar 2006, Dukes Clayton wrote:

> Hii,
> I'm trying to update a table when I do an insert, do I have the syntax
> correct here?
>
>
> destination db_mysql { pipe("/var/log/mysql.pipe"
> template("INSERT INTO logs (host, facility, priority, level, datetime,
> msg)
> VALUES ( '$HOST', '$FACILITY', '$PRIORITY', '$LEVEL', '$YEAR-$MONTH-$DAY
> $HOUR:$MIN:$SEC','$MSG' ) ON INSERT UPDATE NumRows SET
> NumRowsLogs=NumRowsLogs+1;\n")
> template-escape(yes)); };
>
> TIA!
> -Clayton
>


More information about the syslog-ng mailing list