Search code examples
mysqlviewutf-8character-encodinglatin1

Why is my View utf8 and how can I change it to latin1


I'm having an issue where a client program needs to use a View, but it needs the results as latin1. Here's what I've got:

mysql> show global variables like 'character_set%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | latin1                     |
| character_set_connection | latin1                     |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | latin1                     |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

mysql> Select CHARACTER_SET_CLIENT, COLLATION_CONNECTION FROM information_schema.VIEWS v;
+----------------------+----------------------+
| CHARACTER_SET_CLIENT | COLLATION_CONNECTION |
+----------------------+----------------------+
| utf8                 | utf8_general_ci      |
+----------------------+----------------------+

Solution

  • Try running the following commands:

    SET character_set_client = latin1;
    SET character_set_results = latin1;
    SET character_set_connection = latin1;
    DROP VIEW your_view;
    CREATE VIEW your_view as (
        here_goes_your_view_query);
    

    Basically we're recreating the view. I've tested it locally and it worked, even after setting the DB, the table and the column to default to utf8