Bug #74482 A # character cannot be represented in MySQL .ini files
Submitted: 21 Oct 2014 12:42 Modified: 21 Oct 2014 15:28
Reporter: Marlies Heijkoop Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: Options Severity:S3 (Non-critical)
Version:5.5.38 OS:Linux
Assigned to: CPU Architecture:Any
Tags: #, escape, hash, INI, password

[21 Oct 2014 12:42] Marlies Heijkoop
As of MySQL 4.0.14 a #-prefixed comment can start in the middle of a line[1], however, there is no escape sequence for the # character.

Because of the way in which non-existent escape sequences are handled by the parser, \# remains \#, leaving no way to represent a # character in the .ini file format. Note that this is different from how escaping works in SQL statements.

Adding \# as a valid escape sequence for # would solve this issue. The literal string \# could then still be represented as \\#.

Work-around: use a different password or manually enter password on command line

[1] http://dev.mysql.com/doc/refman/4.1/en/option-files.html

How to repeat:
Create a database user with a # in their password, create e.g. a ".my.cnf" file containing the password

With 'password=foo#bar', the password is interpreted as 'foo', connecting fails

With 'password=foo\#bar' the password is interpreted as 'foo\#bar', connecting fails

Have not tested this in other files/options where a # is a valid character.

Suggested fix:
Adding \# (a hash sign prefixed with a backslash) as an escape sequence for # in the option file parser.
[21 Oct 2014 15:28] Miguel Solorzano
Thank you for the bug report.
[25 Oct 2014 8:40] Daniël van Eeden
Tested with 5.6.21.
[25 Oct 2014 8:44] Daniël van Eeden
Tested with 5.6.21:

mysql -u hashpwd -phash\#pwd -- Works
mysql -u hashpwd -p -- Then enter hash#pwd -- Works

This works:

It gets interesting if we start to use login-paths with mysql_config_editor
mysql_config_editor set --login-path=hashpwd --user hashpwd --password

As password input:
hash#pwd -- Doesn't work
hash\#pwd -- Doesn't work
"hash#pwd" -- Does work