Bug #1158 `#' character in password in .my.cnf file is treated as comment delimiter
Submitted: 28 Aug 2003 7:15 Modified: 22 Oct 2003 6:56
Reporter: Martin Mokrejs Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S2 (Serious)
Version:4.0.14 OS:Linux (Linux 2.4.22-pre7)
Assigned to: Jani Tolonen CPU Architecture:Any

[28 Aug 2003 7:15] Martin Mokrejs
Description:
This is a bug not present in 4.0.13 linux official binaries. When user has in ~/.my.cnf:

[mysql]
max_allowed_packet=1G

[client]
user=xx
host=127.0.0.1
password=abc#abc

then the mysql(1) client possible reads only abc from the password and therefore fails to connect.

How to repeat:
[client]
password=abc#abc

ant tro use mysql
[17 Sep 2003 11:12] Jani Tolonen
Fixed in latest source, will appear in 4.0.16 and next 4.1 releases.

The fix is to use quotes in my.cnf around such arguments that
include '#'. The reason is that # starts a comment and thus it
must be quoted. E.g.
[client]
password="abc#def"

Using
password=abc#def

will cause defaults.c to read it as password=abc

However, MySQL prior version 4.0.16 cannot read quoted argument
correctly from my.cnf.

Regards,
Jani
[17 Sep 2003 11:41] Martin Mokrejs
Jani,
  thanks for fix, I just think you should document the change somewhere. Currently, docs say in 3 places the following:

" #comment
    Comment lines start with `#' or `;'. Empty lines are ignored. "

[cut]

"option=value
    This is equivalent to --option=value on the command-line.  "

[cut]

Here is typical user option file:

[client]
# The following password will be sent to all standard MySQL clients
password=my_password

Therefore, I believe this is a change in expected behaviour. I did not have a look into the sources, but I don't understand why mysql takes and a comment `#' sign anywhere else excpet as first character on a line. I'd accept as comment in REGEXP words:

/^\s*#/

but not anything else. If the double-quotes will be required, please document them.

Second, I believe it would be nice if the code reading config files would give user a warning that the syntax of a file is wrong, for example `#' sign not as a first character on a line $number.
[1 Oct 2003 0:30] Martin Mokrejs
No, this is not fixed in bk tree as of 30092003. Still, as my password contains `#' sign, I cannot connect. I have to use "mysql -p" and cut&paste the password from .my.cnf.
[22 Oct 2003 6:56] Jani Tolonen
Documentation fixed. We don't want to restrict using comments
only at the beginning of lines.

Talked with Martin; the source is fixed, the one used earlier did
not yet have the fix.

Regards,
Jani