HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

MySQL datatype for username of maximum 15 characters

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
maximumdatatypeusernamemysqlforcharacters

Problem

I currently have a database with the "user" table having username as one of the columns.

I allow a maximum of 15 characters for the username in my system. Is it fine to have the username column as a varchar(15) datatype?

Solution

The best way to store any short length string in plain text is to use the varchar datatype, setting the maximum length to 15, only for the purpose of integrity. The length of the username should obviously be validated within the application.

The only thing to keep in mind would be the charset of the database, table, and column. Make sure that you are using a charset which covers all of the expected characters in the username, in whatever human language they are being inserted in.

Context

StackExchange Database Administrators Q#45971, answer score: 2

Revisions (0)

No revisions yet.