← Back to team overview

mysql-proxy-discuss team mailing list archive

Re: changing charsets

 

Hi!

On Mar 10, 2009, at 10:03 AM, Thomas Matthijs wrote:

Mysql proxy seems to silently ignore any attempts to change the
charset (set_charset/SET NAMES x).
Would it be possible to make it honor these settings? and are there
any plans to implement this?


Could you elaborate your statement a bit please?
SET NAMES is equivalent to:
SET character_set_client = x; SET character_set_results = x; SET character_set_connection = x;
I've tried this little test:

proxy:4040> show create table utf;
+------- + ---------------------------------------------------------------------------------------+ | Table | Create Table | +------- + ---------------------------------------------------------------------------------------+
| utf   | CREATE TABLE `utf` (
  `a` char(10) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+------- + ---------------------------------------------------------------------------------------+

classdump:trunk kroepke$ echo $LANG
en_US.UTF-8
classdump:trunk kroepke$ echo "insert into utf set a = 'Ä'" | mysql - P4040 -h127.0.0.1 --default-character-set=utf8 test classdump:trunk kroepke$ echo "insert into utf set a = 'Ä'" | mysql -- default-character-set=utf8 test classdump:trunk kroepke$ echo "insert into utf set a = 'Ä'" | mysql -- default-character-set=latin1 test classdump:trunk kroepke$ echo "insert into utf set a = 'Ä'" | mysql - P4040 -h127.0.0.1 --default-character-set=latin1 test classdump:trunk kroepke$ mysql -h127.0.0.1 -P4040 test --default- character-set=utf8

proxy:4040> select hex(a) from utf;
+------------+
| hex(a)     |
+------------+
| C384       |
| C384       |
| C383E2809E |
| C383E2809E |
+------------+
4 rows in set (0.00 sec)

proxy:4040> set names latin1;
Query OK, 0 rows affected (0.00 sec)

proxy:4040> select a from utf;
+------+
| a    |
+------+
| ?     |
| ?     |
| Ä    |
| Ä    |
+------+
4 rows in set (0.00 sec)

proxy:4040> set names utf8;
Query OK, 0 rows affected (0.00 sec)

proxy:4040> select a from utf;
+-------+
| a     |
+-------+
| Ä     |
| Ä     |
| Ä    |
| Ä    |
+-------+
4 rows in set (0.00 sec)

proxy:4040> show variables like 'character_set_%';
+-------------------------- +-----------------------------------------------------+ | Variable_name | Value | +-------------------------- +-----------------------------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/local/mysql-5.1.30-osx10.5-x86/share/ charsets/ | +-------------------------- +-----------------------------------------------------+

IOW, if the charset settings are correct for the client connection, the correct bytes will end up in the database. If the charset settings don't match whatever encoding you use to put them into the mysql client program, then they are screwed up. Now, if you tokenize a query string then we might run into problems right now, is that what you mean?

The above is without a lua script, and the code should simply forward the packets verbatim and not do anything to their encoding. This naturally includes the SET NAMES command. In fact, I cannot see a difference when executing SET NAMES over a proxied connection vs directly connected.

If I'm missing something, I'd like to find out what is not working so we can fix it :)

cheers,
-k
--
Kay Roepke
Software Engineer, MySQL Enterprise Tools

Sun Microsystems GmbH    Sonnenallee 1, DE-85551 Kirchheim-Heimstetten
Geschaeftsfuehrer: Thomas Schroeder, Wolfang Engels, Dr. Roland Boemer
Vorsitz d. Aufs.rat.: Martin Haering                    HRB MUC 161028




References