MySQL Export Escaping paths


I'm trying to export my tag data into a MySQL database, I have a script but its not doing the escaping on the path (I think I need double \ for each directory) and if the filename has ' sign it breaks it completely.

Is there anyway of doing this escaping automatically as part of the export from mp3tag? Current export file below;
Thanks in advanace

$loop(%_title%)INSERT INTO mixed_in_key_data '('track_title, artist, album, track_length, year, genre, bpm, initial_key, energy_level, folder_path ')' VALUES '('"%title%", "%artist%", "%album%", "%_length_seconds%", "%year%", "%genre%", "%BPM%", "%INITIALKEY%", "%ENERGYLEVEL%", "%_path%"')';

I would load the complete file into a text editor like Notepad++ and execute a search & replace for \ with \\ and ' with \' or whatever your database import accepts. Don't forget all the other characters, you have to escape the same way: MySQL :: MySQL 8.0 Reference Manual :: 9.1.1 String Literals

They can occur everywhere in your ARTIST, ALBUM, TITLE...

Do you have any data in %_title%? If not, then you can simply use $loop(1).