I also use bash and gawk and was receiving the same syntax error...until I double escaped characters with special meaning.
sql = "\"INSERT INTO \\`cdr\\`.\\`records\\` (\\`id\\`,\\`session_id\\`,\\`record_id\\`,\\`datum\\`,\\`milisec\\`) VALUES (NULL,'" session_id "','" record_id "','" datum...