Bug #27885 command line clients puke on 'init-command' in my.cnf
Submitted: 17 Apr 2007 15:13 Modified: 5 Dec 2007 18:56
Reporter: Axel Schwenke Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.0.38 OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution

[17 Apr 2007 15:13] Axel Schwenke
The mysql command line clients bail out with an error message like:

mysql: unknown variable 'init-command=...'

when they find the init-command option in the [client] group of an option file. 

According to the manual (http://dev.mysql.com/doc/refman/5.0/en/mysql-options.html) there are a couple of options that libmysqlclient will accept in an option file. Also the [client] group is named as the default group to be read by libmysqlclient. Therefore those options should be allowed in the [client] group of an option file.

However the command line clients treat the [client] group quite differently, trying to parse options from that group on their own and thus error out on options they don't know.

How to repeat:

init-command='set names latin1'

in my.cnf and start a command line client (mysql, mysqldump). Works also with 'multi-statements' and 'multi-results'. 'disable-local-infile' is accepted by mysql, but not by mysqldump. etc.

Suggested fix:
Parsing options from the [client] group should be left to libmysqlclient.

Alternatively: the command line clients should ignore unknown options from the [client] group.
[2 May 2007 19:59] Timothy Smith
It's not immediately obvious how to fix this.  Need to ensure that --totally-bogus-option gives a warning *somewhere* (either in the client, or in libmysqlclient).
[20 Feb 2008 19:53] Omer Barnir
workaround: send the command(s) using an sql script
[3 Jul 2009 1:37] MySQL Verification Team
I looked at the source code, and I think the problem is:

* mysql_real_connect() reads options using mysql_read_default_options() defined in sql-common/client.c, which loads options to struct st_mysql_options using my_load_defaults() defined in mysys/default.c.
* libmysqlclient can read init-command option through mysql_real_connect()
* in client/mysql.cc, options are loaded to global variables using get_options(), get_one_option() and handle_options().

IMHO, mysql should not call mysql_real_connect() using MYSQL_READ_DEFAULT_FILE option. Instead, it should read init-command separately as it does for other options.
[3 Jul 2009 6:36] MySQL Verification Team
I've added a sample patch on bug #45634, which mysql CLI parses --init-command option.

Kind regards,