Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should you accurately specify column types in MySQL?

When I define columns in MySQL I generally use int, varchar(255), text and the occasional enum for boolean. What are the benifits of accurately specifying column types rather than just leaving them at maximum?

For example a password field encoded as MD5 will never exceed 32 characters so is there a tangible performance gain from using varchar(32) over varchar(255)?

like image 382
Meep3D Avatar asked Nov 22 '25 08:11

Meep3D


1 Answers

Per the manual, aVARCHAR(N) of a given actual length takes the same amount of space for any N up to 255, so using 32 saves no space. But there's an advantage of clarity and readability of your schema in using a type that best represents what the actual data must be like.

like image 81
Alex Martelli Avatar answered Nov 23 '25 22:11

Alex Martelli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!