Bug #45634 --init-connect option for mysql CLI
Submitted: 21 Jun 2009 0:59 Modified: 12 Mar 2012 17:30
Reporter: Mikiya Okuno Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S4 (Feature request)
Version: OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution

[21 Jun 2009 0:59] Mikiya Okuno
Description:
Please add --init-connect option to mysql CLI in order to get better usability. Users can add this option in their own .my.cnf file to specify user specific settings.

How to repeat:
n/a

Suggested fix:
n/a
[22 Jun 2009 7:01] Sergei Glukhov
There is 'init-command' option,
see http://dev.mysql.com/doc/refman/5.1/en/mysql-options.html.
[22 Jun 2009 8:21] Mikiya Okuno
Hi Sergey,

Thank you for your reply. But init-command option isn't read from an option file like $HOME/.my.cnf file? It appears that adding init-command option to mysql or libmysqlclient.so so that it is read from an option file isn't so difficult because there's init-command option in C API already.

If init-command option is read from $HOME/.my.cnf, we can specify the option like this:

[client]
init-command="set autocommit=0; set sql_mode=ansi; set tx_isolation='read-committed';"

This can improve our productivity in some way.
[22 Jun 2009 9:44] Sergei Glukhov
Hi Mikiya,
your request is reasonable imho. And unfortunately init-command
does not work ATM :(, see bug#27885.
[3 Jul 2009 6:30] Mikiya Okuno
A patch for 5.1.36

Attachment: init_command.patch (application/octet-stream, text), 4.08 KiB.

[3 Jul 2009 6:35] Mikiya Okuno
Hi Sergey,

I've attached a patch to add --init-connect option for mysql CLI. It works like below:

shell> mysql -uroot -p --init-command="set autocommit=0; set tx_isolation='read-committed'"

In order to make this work, I should modify mysql_real_connect(), because it could not handle multiple statements.

Kind regards,
--
Mikiya
[12 Mar 2012 17:30] Paul Dubois
Noted in 5.5.0 changelog.

The mysql client now supports an --init-command=str option. The
option value is an SQL statement to execute after connecting to the
server. If auto-reconnect is enabled, the statement is executed again
after reconnection occurs.