How to set a varchar to have unlimited length?

前端 未结 5 691
一整个雨季
一整个雨季 2021-02-01 15:10

In a MySQL database, how would I set a varchar to have unlimited length, so that I can store long web pages? IF not , then what is the Maximum Size?

I know about Text Ty

相关标签:
5条回答
  • 2021-02-01 15:36

    VARCHAR can store upto 255 chars before MySQL 5.0.3 and 65,535 chars in 5.0.3 and later versions.

    To store large data in Mysql database you can use

    TEXT , MEDIUMTEXT , LONGTEXT

    TEXT can store 65,535 characters (approx 64KB)
    MEDIUMTEXT = 16,777,215 characters (approx 16 MB) 
    LONGTEXT = 4,294,967,295 chars (approx 4GB)
    
    0 讨论(0)
  • 2021-02-01 15:57

    You can use varchar2. It is better than varchar in many ways

    http://www.orafaq.com/faq/what_is_the_difference_between_varchar_varchar2_and_char_data_types

    Or

    You can try TEXT. It will work for you

    0 讨论(0)
  • 2021-02-01 15:58

    you should try this method: refer this link:

    MySQL - How to increase varchar size of an existing column in a database without breaking existing data?

    alter table table_name modify col_name varchar(10000)
    

    ALTER TABLE `table_name`
       CHANGE COLUMN `col_name` `col_name` VARCHAR(10000);
    

    or otherwise you should use this method:

    TEXT can store 65,535 characters (approx 64KB)
    MEDIUMTEXT = 16,777,215 characters (approx 16 MB) 
    LONGTEXT = 4,294,967,295 chars (approx 4GB)
    
    0 讨论(0)
  • 2021-02-01 15:58

    To answer the other part of his question ...

    Are there any limitations which i have to handle?

    There can be all sorts of unforeseen limits depending on versions of software, data storage engine, etc.

    I encountered these.

    ALTER TABLE reportserver.report ADD reportquery varchar(65535)
    

    Error Code: 1074. Column length too big for column 'reportquery' (max = 21845); use BLOB or TEXT instead

    ALTER TABLE reportserver.report ADD reportquery varchar(21845)
    

    Error Code: 1118. Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs

    You'd probably encounter these when setting up your table or not at all, but rather than risk not being able to add more columns, or not being able to make a column wider, you might want to go the TEXT route straight away if you have seriously wide columns.

    0 讨论(0)
  • 2021-02-01 16:00

    You can try using varchar(max)

    0 讨论(0)
提交回复
热议问题