"""Export MySQL table to an OUTFILE.""" import mysql.connector OUTFILE_SQL = """ SELECT * FROM `{table_name}` INTO OUTFILE '{local_filename}' FIELDS ESCAPED BY '\\\\' TERMINATED BY '\\t' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\\n' """ def dump_table_to_outfile(credentials, table_name, file_path): """Dump table contents to an outfile.""" cnx = mysql.connector.connect(**credentials) cursor = cnx.cursor() cursor.execute(OUTFILE_SQL.format( table_name=table_name, local_filename=file_path)) cursor.close() cnx.close()