Mysql – Extract new lines from log file to MYSQL

MySQL

everyone.

I am new here, I was recommended by Onare, welp, this will be my first question.

I have a file for ex. "file.log" that contains printing logs.

LINE1: PRINTERNAME | userwhichprinted | ID | DATE | 1 | 1 | – | FROMIP | FILENAME | – | –

LINE2: PRINTERNAME | userwhichprinted | ID | DATE | 1 | 1 | – | FROMIP | FILENAME | – | –

LINE3: PRINTERNAME | userwhichprinted | ID | DATE | 1 | 1 | – | FROMIP | FILENAME | – | –

And so on, actually it is a CUPS Server, someone may be familiarized with it.

I want to make a trigger that put every new line to the database. If there are any more questions needed, let me know, thank you in advance.

Best Answer

Perhaps something like the following is what you are looking for?

LOAD DATA LOCAL INFILE '/path/to/raw/data/file.log'
INTO TABLE TABLE_NAME
FIELDS TERMINATED BY '|'
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
;