def set_character_set(self, charset, collation=None):
        """
        Set charaset (and collation)

        Send "SET NAMES charset [COLLATE collation]" query.
        Update Connection.encoding based on charset.
        """
        # Make sure charset is supported.
        encoding = charset_by_name(charset).encoding

        if collation:
            query = f"SET NAMES {charset} COLLATE {collation}"
        else:
            query = f"SET NAMES {charset}"
        self._execute_command(COMMAND.COM_QUERY, query)
        self._read_packet()
        self.charset = charset
        self.encoding = encoding
        self.collation = collation

        Set charaset (and collation)

        Send "SET NAMES charset [COLLATE collation]" query.
        Update Connection.encoding based on charset.
        
pymysql/connections.py