mysql สูงสุดของ field type text

พอดีวันนี้เจอปัญหาของลูกค้าบ่อยๆ คือ การทำ description ที่ใหญ่ๆ แบบ ทำหน้าทั้งหน้าไว้ใน description หรือไป copy มานั่นเอง แล้วเราก็กำหนด description เป็น type text แล้ว แต่ดันเก็บไม่พอ 555 ใหญ่เกินนั้นเอง เวลาแสดงหน้าเว็บเลย เรียกว่าผิดรูปกันไปเลยทีเดียวเลยไปหาว่า type text เก็บได้เท่าใหร่ไปเจอที่ หนึ่งคือ http://simonwillison.net/2002/Aug/1/mysqlTextLimits/

เค้าได้บอกไว้ว่า

Today’s scary discovery: MySQL TEXT fields have a limit of 65,000 bytes. If you insert anything larger than that in to a normal TEXT field mySQL will silently truncate your data without telling you (meaning software checks are probably a good idea). MEDIUMTEXT will store 16 million characters and LONGTEXT can handle over 4 trillion, but this information does not appear to be readily available in the online mySQL manual (although it is hinted at in this table). Something to bare in mind when designing database applications.

ตรงส่วนที่เขียวก็คือปริมาณในการเก็บของแต่ละ type นั้นเอง

text จะเก็บได้ 65,000 byte นั้นเอง ถ้าคิดเป็น utf แล้วเก็บภาษาไทยก็ยิ่งน้อยไปใหญ่

mediumtext เก็บได้ 16 million byte หรือ 16 ล้าน หรือ 16 MB เพิ่มมา 240 กว่าเท่าก็ใหญ่พอควร ในการเก็บข้อมูลที่ใหญ่ แค่นี้ก้พอแล้วนะสำหรับ description ที่ copy html มาของลูกค้า แต่ก็มีอีกอันที่ใหญ่กว่าคือ

longtext นี่เก็ยได้เิบิ้มเลย 4 trillion หรือ 4 แสนล้าน นั้นเอง

database แค่ record เดียวโตมากๆไม่ดีนะ ดูที่ความจำกัดเวลาใช้ด้วย

Leave a Reply

You must be logged in to post a comment.