I have a web-based project written in Perl and MySQL. we use template toolkit for rendering the HTML page. we have written a custom wrapper on DBI class to interact with MySQL.
Since it is a legacy project, most of our tables are latin1 charset. Recently we started supporting Multi-language UI ( Spanish and Arabic ). Because of this, Users are entering the data in their native languages. The data is not encoded and it is saved into the DB. Now we have a ETL process which moves data from our primary DB to star schema DB which are UTF8 tables. This DB is used only for reports. Now in one of the reports we are getting unreadable characters.
I am changing the query to retrieve this data as
SET NAMES latin1;
select
CONVERT(CAST(CONVERT( label USING latin1) AS BINARY) USING utf8) AS label
from report_table
where report_id = '999';
I am using sqlyug to execute the query. If I do not set the SET NAMES latin1;, then the value is still not readable. But when I am trying the same change in the code level, I am not able to get the application display the data correctly. In our custom DB wrapper we are not setting any particular settings.
we are not setting SET character_set_results.
we are not even setting enable_utf8 => 0,
I am not sure what needs to be done.
I know it is a better solution to correct the data in the primary DB before ETL but it is a long term plan. I need some solution which can fix the issue temporarily and not block the customers.
Let me know if you need any more information.

Try enabling UTF-8 for the DB connection as such:
$dbh->{'mysql_enable_utf8'} = 1;As I remember, using
SET NAMESis not the most recommended way to do this, but in case you want to use it, should you trySET NAMES utf8instead of latin1