Fixed the problem when the exported PV was disconnected and the file was closed too early.
Updated the mysql statement to insert ignore into.