I want save randomly generated 20 character's alpha-numeric in mysql. What type of fields is better choice? varchar, binarym
Asked
Active
Viewed 148 times
0
-
1If you want alpha-numeric values, store them as strings. If they are always 20 characters, use `char(20)`; otherwise `varchar(20)`. – Gordon Linoff Jan 21 '15 at 12:32
-
Google: *mysql generate random string* – juergen d Jan 21 '15 at 12:32
1 Answers
0
The best would be CHAR(20)
.
But if you need to choose between varcher
or binary
, choose VARCHAR(20)
.
Here is a discussion how to generate a random string using SQL in case you want the generation to happen in MySQL
: Generating a random & unique 8 character string using MySQL

Community
- 1
- 1

Plamen Nikolov
- 2,643
- 1
- 13
- 24