mysql - Is char or varchar better for a database with utf-8 encoding? -


i making table of users store info: username, password, etc. question is: better store usernames in varchar utf-8 encoded table or in char. asking because char 1 byte , utf-8 encodes 3 bytes characters , not know whether might lose data. possible use char in case or have use varchar?

in general, rule use char encoding under following circumstances:

  • you have short codes same length (think state abbreviations).
  • sometimes when have short code might differ in length, can count characters on 1 hand.
  • when powers-that-be have use char.
  • when want demonstrate how padding spaces @ end of string causes unexpected behavior.

in other cases, use varchar(). in practice, users of database don't expect bunch of spaces @ end of strings.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -