Mysql – Username length restriction in different MySQL environments

MySQLusers

I am setting up a project to my local environment and at its initial script are some SQL commands for creating the database:

  • create database 'db-name' default character set utf8;

and to grant privileges for the user account:

  • grant select, insert, update, delete, create, drop, index, alter on 'db-name'.* to 'user-name-too-long-for-user-name'@'localhost' identified by 'user-name-pass'

When I am trying to run the grant command I get this:

  • ERROR 1470 (HY000): String 'user-name-to-long-for-user-name' is too long for user name (should be no longer than 16)

and I can't understand why is this happening whereas this same script has successfully run to another environment before it comes to mine.

The server version I am using is 5.6.20 MySQL Community Server (GPL).

Is this situation related to a certain MySQL version or something else?

Best Answer

The maximum length for a user name in MySQL does depend on the version, as stated in the manual:

MySQL user names can be up to 32 characters long (16 characters before MySQL 5.7.8).