Bug #21548 Username limited to 16 bytes, not chars - non-latin1 usernames limited to 8chars
Submitted: 9 Aug 2006 17:28 Modified: 22 Sep 2006 9:32
Reporter: Andrey Hristov Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Charsets Severity:S2 (Serious)
Version:5.0,5.1;4.1BK OS:
Assigned to: Assigned Account CPU Architecture:Any

[9 Aug 2006 17:28] Andrey Hristov
Description:
The maximal length of user name is limited to 16 bytes, not 16 chars. This could be seen by using non-latin1 characters, for example cyrillic:

--here are 6*2 + 1 = 13 bytes  (_ is only one byte)
mysql> grant all on *.* to андрей_@localhost;
Query OK, 0 rows affected (0.02 sec)

--here are 7*2 + 1 = 15 bytes
mysql> grant all on *.* to андрей_й@localhost;
Query OK, 0 rows affected (0.02 sec)

--here are 8*2 + 1 = 17 bytes (_ is only one byte)
mysql> grant all on *.* to андрей_йо@localhost;
ERROR 1145 (42000): The host or user argument to GRANT is too long

mysq.proc has the following structure:
CREATE TABLE `user` (
  `Host` char(60) collate utf8_bin NOT NULL default '',
  `User` char(16) collate utf8_bin NOT NULL default '',
 ..
);

However, there is a server-wide macro in mysql_com.h:
#define USERNAME_LENGTH 16

It is used for checking and allocating buffers on the stack. Current usage of USERNAME_LENGTH has to be changed to use character sets. Actually the max length will be 16*3 bytes. Probably an introduction of a new macro will be needed. This problem is similar to the one of the length of table names limited again by bytes not chars, rendering names not in Latin1 longer than 32 characters forbidden.

How to repeat:
grant all on *.* to андрей_@localhost;
grant all on *.* to андрей_й@localhost;
grant all on *.* to андрей_йо@localhost;
[10 Aug 2006 2:21] MySQL Verification Team
Thank you for the bug report.

miguel@light:~/dbs/5.0> bin/mysql -uroot --default-character-set=utf8
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.25-debug

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> grant all on *.* to андрей_@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on *.* to андрей_й@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on *.* to андрей_йо@localhost;
ERROR 1145 (42000): The host or user argument to GRANT is too long
mysql>

miguel@light:~/dbs/5.1> bin/mysql -uroot --default-character-set=utf8
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.1.12-beta-debug

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> grant all on *.* to андрей_@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on *.* to андрей_й@localhost;
Query OK, 0 rows affected (0.00 sec)

miguel@light:~/dbs/4.1> bin/mysql -uroot --default-character-set=utf8
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.22-debug

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> grant all on *.* to андрей_@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on *.* to андрей_й@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on *.* to андрей_йо@localhost;
ERROR 1145 (42000): The host or user argument to GRANT is too long
mysql>                

mysql> grant all on *.* to андрей_йо@localhost;
ERROR 1145 (42000): The host or user argument to GRANT is too long
mysql>
[22 Sep 2006 9:32] Sergei Glukhov
Diplicate with Bug#20393 "User name truncation in mysql client"