Bug #32753 PAD_CHAR_TO_FULL_LENGTH is not documented and interferes with grant tables
Submitted: 27 Nov 2007 7:09 Modified: 12 Apr 2008 1:46
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:5.1.23 OS:Any
Assigned to: Tatiana Azundris Nuernberg CPU Architecture:Any
Tags: PAD_CHAR_TO_FULL_LENGTH

[27 Nov 2007 7:09] Shane Bester
Description:
I lost the ability to connect to my server after executing the following:

mysql> set global sql_mode='PAD_CHAR_TO_FULL_LENGTH';
Query OK, 0 rows affected (0.00 sec)

mysql> \r
Connection id:    2
Current database: test

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> \r
ERROR 1130 (00000): Host '192.168.250.4' is not allowed to connect to this MySQL server
mysql>

The reason is that the user names in my grant tables become space-padded!!

See this which might be related:

ChangeSet@1.2572, 2007-04-27 01:12:09+03:00, monty@mysql.com +11 -0
Added sql_mode PAD_CHAR_TO_FULL_LENGTH (WL#921)

How to repeat:
connect to your server and paste the following in mysql command line client:

set global sql_mode='PAD_CHAR_TO_FULL_LENGTH';
\r
flush privileges;
\r

Suggested fix:
Document this sql_mode and it's side-affects.  Consider what effects it has on grant tables?
[7 Jan 2008 5:30] 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/40613

ChangeSet@1.2588, 2008-01-07 06:30:41+01:00, tnurnberg@mysql.com +3 -0
  Bug#32753: PAD_CHAR_TO_FULL_LENGTH is not documented and interferes with grant tables
  
  SQL-mode PAD_CHAR_TO_FULL_LENGTH affected mysqld's user-table too. If
  enabled, user-name and host were space-padded and no longer matched
  the login-data of incoming connexions.
  
  Patch disregards pad-flag while loading privileges so ability to log
  in does not depend on SQL-mode.
[7 Jan 2008 5:44] Tatiana Azundris Nuernberg
doc notes:

SQL-mode PAD_CHAR_TO_FULL_LENGTH prevents
automatic trimming of trailing white-space
in CHAR() (but not VARCHAR()) fields:

create table t1 ( f1 varchar(32), f2 char(32));
insert into t1 values ('katze','keks');
set session sql_mode='PAD_CHAR_TO_FULL_LENGTH';
select * from t1;
+-------+----------------------------------+
| f1    | f2                               |
+-------+----------------------------------+
| katze | keks                             | 
+-------+----------------------------------+

set session sql_mode='';
select * from t1;
+-------+------+
| f1    | f2   |
+-------+------+
| katze | keks | 
+-------+------+

Since user-data are stored in a table (an implementation detail),
they were also affected, making the credentials in the server
look different from those provided by users trying to log in.
While

select host,user,password from mysql.user;

still heeds the pad-flag, we internally failsafe against this
case to prevent users from locking themselves out of the server
until restart.
[7 Jan 2008 5:47] Tatiana Azundris Nuernberg
bug verified as not existent before 5.1
[24 Feb 2008 11:32] 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/42916

ChangeSet@1.2668, 2008-02-24 12:32:17+01:00, tnurnberg@mysql.com +3 -0
  Bug#32753: PAD_CHAR_TO_FULL_LENGTH is not documented and interferes with grant tables
  
  SQL-mode PAD_CHAR_TO_FULL_LENGTH affected mysqld's user-table too. If
  enabled, user-name and host were space-padded and no longer matched
  the login-data of incoming connexions.
  
  Patch disregards pad-flag while loading privileges so ability to log
  in does not depend on SQL-mode.
[25 Feb 2008 2:05] Tatiana Azundris Nuernberg
pushed to 5.1.24-rc, 6.0.5-alpha in opt
[13 Mar 2008 19:29] Bugs System
Pushed into 6.0.5-alpha
[13 Mar 2008 19:36] Bugs System
Pushed into 5.1.24-rc
[31 Mar 2008 19:42] Jon Stephens
Pushed into 5.1.23-ndb-6.3.11.
[12 Apr 2008 1:46] Paul DuBois
Noted in 5.1.24, 6.0.5 changelogs.

Enabling the PAD_CHAR_TO_FULL_LENGTH SQL mode caused 
privilege-loading operations (such as FLUSH PRIVILEGES) to include
trailing spaces from grant table values stored in CHAR columns.
Authentication for incoming connections failed as a result. Now
privilege loading does not include trailing spaces, regardless of SQL
mode.   

Also documented the PAD_CHAR_TO_FULL_LENGTH mode at
http://dev.mysql.com/doc/refman/5.1/en/server-sql-mode.html :

By default, trailing spaces are trimmed from CHAR column values on
retrieval. If PAD_CHAR_TO_FULL_LENGTH is enabled, trimming does not 
occur and retrieved CHAR values are padded to their full length. This
mode does not apply to VARCHAR columns, for which trailing spaces are
retained on retrieval.  

This mode was added in 5.1.20.