Bug #51166 mysql client defaults to charset 'ascii'
Submitted: 13 Feb 2010 20:26 Modified: 27 Aug 2010 14:58
Reporter: Aleksandar Ivanisevic Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Packaging Severity:S3 (Non-critical)
Version:MySQL-client-5.5.1_m2-1.glibc23 OS:Linux (rhel5)
Assigned to: Alexander Barkov CPU Architecture:Any
Tags: character set, regression

[13 Feb 2010 20:26] Aleksandar Ivanisevic
Description:

mysql client from MySQL-client-5.5.1_m2-1.glibc23 rpm package defaults to character set 'ascii', but the definition of it is actually contained in the server package

this results in errors like this when mysql command line is ran from environment where LANG is undefined, i.e. crontab

mysql: Character set 'ascii' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file

How to repeat:
$ rpm -qa | grep -i ^mysql
MySQL-shared-compat-5.5.1_m2-1.glibc23
MySQL-client-5.5.1_m2-1.glibc23

$  LANG= mysql -hxx -uyy -pzz -e"show variables like '%character_set%'"
mysql: Character set 'ascii' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file
ERROR 2019 (HY000): Can't initialize character set ascii (path: /usr/share/mysql/charsets/)

Suggested fix:
default to a built-in character set or supply a default
[15 Feb 2010 6:35] Sveta Smirnova
Thank you for the report.

Verified as described.
[15 Feb 2010 8:43] Aleksandar Ivanisevic
I'm sorry but I don't think that supplying a default character set is a feature request.

This is a bug, as it clearly breaks compatibility, it sure broke tons of my scripts.

I think than, when in doubt, the client should default to latin1, like its predecessors.
[15 Feb 2010 9:21] Daniel Fischer
The bug appears to be caused by wl#1349, where we try to map the OS character set to a MySQL character set in sql-common/client.c:my_os_charset_to_mysql_charset(). The OS character set is determined by calling nl_langinfo() where available. On Linux, this function is available, and when no locale is set, returns the name "ANSI_X3.4-1968". The mapping between OS names and MySQL names for character sets (same source file as above) assigns the MySQL character set "ascii" to this OS character set. However, the MySQL character set "ascii" is not necessarily available. The bug is that my_os_charset_to_mysql_charset() can pick a MySQL character set that is not available.
[4 Mar 2010 11:22] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/102282

3106 Alexander Barkov	2010-03-04
      Bug#51166 mysql client defaults to charset 'ascii' 
      Using latin1 client character set for ASCII locales:
      - because ascii is not a build-in character set
      - for better backward compatibility
[6 Mar 2010 10:29] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20100306102742-yw9zzgw9ac5r65m5) (version source revid:bar@mysql.com-20100304132546-mg01i2tr3lbdx0n6) (merge vers: 6.0.14-alpha) (pib:16)
[6 Mar 2010 10:31] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100306102638-qna09hbjb5gm940h) (version source revid:bar@mysql.com-20100304111346-zvle5vvkfwzwf9x5) (pib:16)
[6 Mar 2010 10:53] Bugs System
Pushed into 5.5.3-m3 (revid:alik@sun.com-20100306103849-hha31z2enhh7jwt3) (version source revid:bar@mysql.com-20100304111346-zvle5vvkfwzwf9x5) (merge vers: 5.5.99-m3) (pib:16)
[27 Aug 2010 12:58] MC Brown
A note has been added to the 6.0.14 and 5.5.3 changelogs: 

        The <command>mysql</command> could default to                                                                                                      
        the <literal>ascii</literal> character set, which is not a                                                                                         
        valid character set choice for                                                                                                                     
        MySQL. The <literal>latin1</literal> character set will now be                                                                                     
        used when an ASCII environment has been identified.