MySQL 如何将varchar设置为无限长度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22756583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set a varchar to have unlimited length?
提问by Birlla
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?
在 MySQL 数据库中,如何将 varchar 设置为无限长度,以便我可以存储长网页?如果不是,那么最大尺寸是多少?
I know about Text Types to store larger strings. Is there any limitations on using test data type which i have to handle?
我知道文本类型可以存储更大的字符串。使用我必须处理的测试数据类型有什么限制吗?
回答by Rupam
VARCHAR can store upto 255 chars before MySQL 5.0.3 and 65,535 chars in 5.0.3 and later versions.
VARCHAR 在 MySQL 5.0.3 之前最多可以存储 255 个字符,在 5.0.3 及更高版本中最多可以存储 65,535 个字符。
To store large data in Mysql database you can use
要将大数据存储在 Mysql 数据库中,您可以使用
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)
回答by HaydnJW
You can try using varchar(max)
您可以尝试使用 varchar(max)
回答by jmail
you should try this method: refer this link:
你应该试试这个方法:参考这个链接:
MySQL - 如何在不破坏现有数据的情况下增加数据库中现有列的 varchar 大小?
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)
回答by Ivan
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
错误代码:1074。列“reportquery”的列长度太大(最大值 = 21845);改用 BLOB 或 TEXT
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
错误代码:1118。行大小太大。所用表类型的最大行大小(不包括 BLOB)为 65535。这包括存储开销,请查看手册。您必须将某些列更改为 TEXT 或 BLOB
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.
您可能会在设置表格时遇到这些问题,或者根本不会遇到这些问题,但与其冒着无法添加更多列或无法使列更宽的风险,不如直接走 TEXT 路线,如果您有非常宽的列。
回答by Amrit Singh
You can use varchar2. It is better than varchar in many ways
您可以使用 varchar2。它在很多方面都比 varchar 好
http://www.orafaq.com/faq/what_is_the_difference_between_varchar_varchar2_and_char_data_types
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
你可以试试文本。它会为你工作