[MySqL] ¹ØÓÚMySqlÖеÄvarcharÀàÐÍ
1¡¢varcharÀàÐ͵ı仯MySQL Êý¾Ý¿âµÄvarcharÀàÐÍÔÚ4.1ÒÔϵİ汾ÖеÄ×î´ó³¤¶ÈÏÞÖÆΪ255£¬ÆäÊý¾Ý·¶Î§¿ÉÒÔÊÇ0~255»ò1~255£¨¸ù¾Ý²»Í¬°æ±¾Êý¾Ý¿âÀ´¶¨£©¡£ÔÚ MySQL5.0ÒÔÉϵİ汾ÖУ¬varcharÊý¾ÝÀàÐ͵ij¤¶ÈÖ§³Öµ½ÁË65535£¬Ò²¾ÍÊÇ˵¿ÉÒÔ´æ·Å65532¸ö×Ö½ÚµÄÊý¾Ý£¬ÆðʼλºÍ½áÊøλռȥÁË3¸ö×Ö ½Ú£¬Ò²¾ÍÊÇ˵£¬ÔÚ4.1»òÒÔÏ°汾ÖÐÐèҪʹÓù̶¨µÄTEXT»òBLOB¸ñʽ´æ·ÅµÄÊý¾Ý¿ÉÒÔʹÓÿɱ䳤µÄvarcharÀ´´æ·Å£¬ÕâÑù¾ÍÄÜÓÐЧµÄ¼õÉÙÊý¾Ý¿âÎÄ ¼þµÄ´óС¡£
MySQL Êý¾Ý¿âµÄvarcharÀàÐÍÔÚ4.1ÒÔϵİ汾ÖÐ,nvarchar£¨´æ´¢µÄÊÇUnicodeÊý¾ÝÀàÐ͵Ä×Ö·û£©²»¹ÜÊÇÒ»¸ö×Ö·û»¹ÊÇÒ»¸öºº×Ö,¶¼´æΪ2¸ö×Ö ½Ú £¬Ò»°ãÓÃ×÷ÖÐÎÄ»òÕßÆäËûÓïÑÔÊäÈ룬ÕâÑù²»ÈÝÒ×ÂÒÂë ;varchar: ºº×ÖÊÇ2¸ö×Ö½Ú,ÆäËû×Ö·û´æΪ1¸ö×Ö½Ú £¬varcharÊʺÏÊäÈëÓ¢ÎĺÍÊý×Ö¡£
4.0°æ±¾ÒÔÏ£¬varchar(20)£¬Ö¸µÄÊÇ20×Ö½Ú£¬Èç¹û´æ·ÅUTF8ºº×Öʱ£¬Ö»ÄÜ´æ6¸ö£¨Ã¿¸öºº×Ö3×Ö½Ú£© £»5.0°æ±¾ÒÔÉÏ£¬varchar(20)£¬Ö¸µÄÊÇ20×Ö·û£¬ÎÞÂÛ´æ·ÅµÄÊÇÊý×Ö¡¢×Öĸ»¹ÊÇUTF8ºº×Ö£¨Ã¿¸öºº×Ö3×Ö½Ú£©£¬¶¼¿ÉÒÔ´æ·Å20¸ö£¬×î´ó´óСÊÇ 65532×Ö½Ú £»varchar(20)ÔÚMysql4ÖÐ×î´óÒ²²»¹ýÊÇ20¸ö×Ö½Ú,µ«ÊÇMysql5¸ù¾Ý±àÂ벻ͬ,´æ´¢´óСҲ²»Í¬£¬¾ßÌåÓÐÒÔϹæÔò£º
a) ´æ´¢ÏÞÖÆ
varchar ×Ö¶ÎÊǽ«Êµ¼ÊÄÚÈݵ¥¶À´æ´¢ÔÚ¾Û´ØË÷ÒýÖ®Í⣬ÄÚÈÝ¿ªÍ·ÓÃ1µ½2¸ö×Ö½Ú±íʾʵ¼Ê³¤¶È£¨³¤¶È³¬¹ý255ʱÐèÒª2¸ö×Ö½Ú£©£¬Òò´Ë×î´ó³¤¶È²»Äܳ¬¹ý65535¡£
b) ±àÂ볤¶ÈÏÞÖÆ
×Ö·ûÀàÐÍÈôΪgbk£¬Ã¿¸ö×Ö·û×î¶àÕ¼2¸ö×Ö½Ú£¬×î´ó³¤¶È²»Äܳ¬¹ý32766;
×Ö·ûÀàÐÍÈôΪutf8£¬Ã¿¸ö×Ö·û×î¶àÕ¼3¸ö×Ö½Ú£¬×î´ó³¤¶È²»Äܳ¬¹ý21845¡£
Èô¶¨ÒåµÄʱºò³¬¹ýÉÏÊöÏÞÖÆ£¬Ôòvarchar×ֶλᱻǿÐÐתΪtextÀàÐÍ£¬²¢²úÉúwarning¡£
c) Ð㤶ÈÏÞÖÆ
µ¼ÖÂʵ¼ÊÓ¦ÓÃÖÐvarchar³¤¶ÈÏÞÖƵÄÊÇÒ»¸öÐж¨ÒåµÄ³¤¶È¡£ MySQLÒªÇóÒ»¸öÐеĶ¨Ò峤¶È²»Äܳ¬¹ý65535¡£Èô¶¨ÒåµÄ±í³¤¶È³¬¹ýÕâ¸öÖµ£¬ÔòÌáʾ
ERROR 1118 (42000): Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. You have to change some columns to TEXT or BLOBs¡£
2¡¢CHAR(M), VARCHAR(M)²»Í¬Ö®´¦CHAR(M)¶¨ÒåµÄÁеij¤¶ÈΪ¹Ì¶¨µÄ£¬MÈ¡Öµ¿ÉÒÔΪ0¡«255Ö®¼ä£¬µ±±£´æCHARֵʱ£¬ÔÚËüÃǵÄÓÒ±ßÌî³ä¿Õ¸ñÒÔ´ïµ½Ö¸¶¨µÄ³¤¶È¡£µ±¼ì Ë÷µ½CHARֵʱ£¬Î²²¿µÄ¿Õ¸ñ±»É¾³ýµô¡£ÔÚ´æ´¢»ò¼ìË÷¹ý³ÌÖв»½øÐдóСдת»»¡£CHAR´æ´¢¶¨³¤Êý¾ÝºÜ·½±ã£¬CHAR×Ö¶ÎÉϵÄË÷ÒýЧÂʼ¶¸ß£¬±ÈÈ綨Òå char(10)£¬ÄÇô²»ÂÛÄã´æ´¢µÄÊý¾ÝÊÇ·ñ´ïµ½ÁË10¸ö×Ö½Ú£¬¶¼ÒªÕ¼È¥10¸ö×ֽڵĿռä,²»×ãµÄ×Ô¶¯ÓÿոñÌî³ä¡£
VARCHAR(M)¶¨ÒåµÄÁеij¤¶ÈΪ¿É±ä³¤×Ö·û´®£¬MÈ¡Öµ¿ÉÒÔΪ0~65535Ö®¼ä£¬(VARCHARµÄ×î´óÓÐЧ³¤¶ÈÓÉ×î´óÐдóСºÍʹÓà µÄ×Ö·û¼¯È·¶¨¡£ÕûÌå×î´ó³¤¶ÈÊÇ65,532×Ö½Ú£©¡£VARCHARÖµ±£´æʱֻ±£´æÐèÒªµÄ×Ö·ûÊý£¬Áí¼ÓÒ»¸ö×Ö½ÚÀ´¼Ç¼³¤¶È(Èç¹ûÁÐÉùÃ÷µÄ³¤¶È³¬¹ý255£¬Ôò ʹÓÃÁ½¸ö×Ö½Ú)¡£VARCHARÖµ±£´æʱ²»½øÐÐÌî³ä¡£µ±Öµ±£´æºÍ¼ìË÷ʱβ²¿µÄ¿Õ¸ñÈÔ±£Áô£¬·ûºÏ±ê×¼SQL¡£varchar´æ´¢±ä³¤Êý¾Ý£¬µ«´æ´¢Ð§ÂÊûÓÐ CHAR¸ß¡£Èç¹ûÒ»¸ö×ֶοÉÄܵÄÖµÊDz»¹Ì¶¨³¤¶ÈµÄ£¬ÎÒÃÇÖ»ÖªµÀËü²»¿ÉÄܳ¬¹ý10¸ö×Ö·û£¬°ÑËü¶¨ÒåΪ VARCHAR(10)ÊÇ×îºÏËãµÄ¡£VARCHARÀàÐ͵Äʵ¼Ê³¤¶ÈÊÇËüµÄÖµµÄʵ¼Ê³¤¶È+1¡£ÎªÊ²Ã´¡±+1¡åÄØ£¿ÕâÒ»¸ö×Ö½ÚÓÃÓÚ±£´æʵ¼ÊʹÓÃÁ˶à´óµÄ³¤¶È¡£ ´Ó¿Õ¼äÉÏ¿¼ÂÇ£¬ÓÃvarcharºÏÊÊ£»´ÓЧÂÊÉÏ¿¼ÂÇ£¬ÓÃcharºÏÊÊ£¬¹Ø¼üÊǸù¾Ýʵ¼ÊÇé¿öÕÒµ½È¨ºâµã¡£
CHARºÍVARCHAR×î´óµÄ²»Í¬¾ÍÊÇÒ»¸öÊǹ̶¨³¤¶È£¬Ò»¸öÊǿɱ䳤¶È¡£ÓÉÓÚÊǿɱ䳤¶È£¬Òò´Ëʵ¼Ê´æ´¢µÄʱºòÊÇʵ¼Ê×Ö·û´®ÔÙ¼ÓÉÏÒ»¸ö¼Ç¼ ×Ö·û´®³¤¶ÈµÄ×Ö½Ú(Èç¹û³¬¹ý255ÔòÐèÒªÁ½¸ö×Ö½Ú)¡£Èç¹û·ÖÅä¸øCHAR»òVARCHARÁеÄÖµ³¬¹ýÁеÄ×î´ó³¤¶È£¬Ôò¶ÔÖµ½øÐвüôÒÔʹÆäÊʺϡ£Èç¹û±»²Ãµô µÄ×Ö·û²»ÊÇ¿Õ¸ñ£¬Ôò»á²úÉúÒ»Ìõ¾¯¸æ¡£Èç¹û²Ã¼ô·Ç¿Õ¸ñ×Ö·û£¬Ôò»áÔì³É´íÎó(¶ø²»ÊǾ¯¸æ)²¢Í¨¹ýʹÓÃÑϸñSQLģʽ½ûÓÃÖµµÄ²åÈë¡£
3¡¢VARCHARºÍTEXT¡¢BlOBÀàÐ͵ÄÇø±ðVARCHAR£¬BLOBºÍTEXTÀàÐÍÊDZ䳤ÀàÐÍ£¬¶ÔÓÚÆä´æ´¢ÐèÇóÈ¡¾öÓÚÁÐÖµµÄʵ¼Ê³¤¶È(ÔÚÇ°ÃæµÄ±í¸ñÖÐÓÃL±íʾ)£¬¶ø²»ÊÇÈ¡¾öÓÚÀàÐÍ µÄ×î´ó¿ÉÄܳߴ硣ÀýÈ磬һ¸öVARCHAR(10)ÁÐÄܱ£´æ×î´ó³¤¶ÈΪ10¸ö×Ö·ûµÄÒ»¸ö×Ö·û´®£¬Êµ¼ÊµÄ´æ´¢ÐèÒªÊÇ×Ö·û´®µÄ³¤¶È £¬¼ÓÉÏ1¸ö×Ö½ÚÒԼǼ×Ö·û´®µÄ³¤¶È¡£¶ÔÓÚ×Ö·û´®¡¯abcd¡¯£¬LÊÇ4¶ø´æ´¢ÒªÇóÊÇ5¸ö×Ö½Ú¡£
BLOBºÍTEXTÀàÐÍÐèÒª1£¬2£¬3»ò4¸ö×Ö½ÚÀ´¼Ç¼ÁÐÖµµÄ³¤¶È£¬ÕâÈ¡¾öÓÚÀàÐ͵Ä×î´ó¿ÉÄܳ¤¶È¡£VARCHARÐèÒª¶¨Òå´óС£¬ÓÐ65535×Ö½ÚµÄ×î´óÏÞÖÆ£»TEXTÔò²»ÐèÒª¡£Èç¹ûÄã°ÑÒ»¸ö³¬¹ýÁÐÀàÐÍ×î´ó³¤¶ÈµÄÖµ¸³¸øÒ»¸öBLOB»òTEXTÁУ¬Öµ±»½Ø¶ÏÒÔÊʺÏËü¡£
Ò»¸öBLOBÊÇÒ»¸öÄܱ£´æ¿É±äÊýÁ¿µÄÊý¾ÝµÄ¶þ½øÖƵĴó¶ÔÏó¡£4¸öBLOBÀàÐÍTINYBLOB¡¢BLOB¡¢MEDIUMBLOBºÍLONGBLOB½ö½öÔÚËûÃÇÄܱ£´æÖµµÄ×î´ó³¤¶È·½ÃæÓÐËù²»Í¬¡£
BLOB ¿ÉÒÔ´¢´æͼƬ£¬TEXT²»ÐУ¬TEXTÖ»ÄÜ´¢´æ´¿Îı¾Îļþ¡£4¸öTEXTÀàÐÍTINYTEXT¡¢TEXT¡¢MEDIUMTEXTºÍLONGTEXT¶ÔÓ¦ÓÚ 4¸öBLOBÀàÐÍ£¬²¢ÇÒÓÐͬÑùµÄ×î´ó³¤¶ÈºÍ´æ´¢ÐèÇó¡£ÔÚBLOBºÍTEXTÀàÐÍÖ®¼äµÄΨһ²î±ðÊǶÔBLOBÖµµÄÅÅÐòºÍ±È½ÏÒÔ´óСдÃô¸Ð·½Ê½Ö´ÐУ¬¶ø¶Ô TEXTÖµÊÇ´óСд²»Ãô¸ÐµÄ¡£»»¾ä»°Ëµ£¬Ò»¸öTEXTÊÇÒ»¸ö´óСд²»Ãô¸ÐµÄBLOB¡£
4¡¢×ܽáchar£¬varcharºÍtextµÄÇø±ð³¤¶ÈµÄÇø±ð£¬char·¶Î§ÊÇ0¡«255£¬varchar×ÊÇ64k£¬µ«ÊÇ×¢ÒâÕâÀïµÄ64kÊÇÕû¸örowµÄ³¤¶È£¬Òª¿¼Âǵ½ÆäËüµÄ column£¬»¹ÓÐÈç¹û´æÔÚnot nullµÄʱºòÒ²»áÕ¼ÓÃһ룬¶Ô²»Í¬µÄ×Ö·û¼¯£¬ÓÐЧ³¤¶È»¹²»Ò»Ñù£¬±ÈÈçutf8µÄ£¬×î¶à21845£¬»¹Òª³ýÈ¥±ðµÄcolumn£¬µ«ÊÇvarcharÔÚÒ»°ã Çé¿öÏ´洢¶¼¹»ÓÃÁË¡£Èç¹ûÓöµ½ÁË´óÎı¾£¬¿¼ÂÇʹÓÃtext£¬×î´óÄܵ½4G¡£
ЧÂÊÀ´Ëµ»ù±¾ÊÇchar>varchar>text£¬µ«ÊÇÈç¹ûʹÓõÄÊÇInnodbÒýÇæµÄ»°£¬ÍƼöʹÓÃvarchar´úÌæchar¡£
charºÍvarchar¿ÉÒÔÓÐĬÈÏÖµ£¬text²»ÄÜÖ¸¶¨Ä¬ÈÏÖµ¡£
Êý¾Ý¿âÑ¡ÔñºÏÊʵÄÊý¾ÝÀàÐÍ´æ´¢»¹ÊǺÜÓбØÒªµÄ£¬¶ÔÐÔÄÜÓÐÒ»¶¨Ó°Ïì¡£ÕâÀïÔÚÁãËé¼Ç¼Á½±Ê£¬¶ÔÓÚintÀàÐ͵ģ¬Èç¹û²»ÐèÒª´æÈ¡¸ºÖµ£¬×îºÃ¼ÓÉÏunsigned£»¶ÔÓÚ¾³£³öÏÖÔÚwhereÓï¾äÖеÄ×ֶΣ¬¿¼ÂǼÓË÷Òý£¬ÕûÐεÄÓÈÆäÊʺϼÓË÷Òý¡£
ÍƼöÐÅÏ¢
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
ÆÀÂÛ