为什么MySQL忽略了列的数据类型长度?
我正在使用MySQL 8.0,并且正在尝试将URL存储在列中。每当我尝试插入超过191个字符的URL时,我都会收到以下错误:
1406 Data too long for column 'url' at row 1
列数据类型为varchar(1000),URL为〜450个字符。我尝试插入其他字符串和任何191个字符,并且在工作中正常,但是在191个字符上没有什么能做的。
我尝试将此列的数据类型更改为其他字符串格式,例如文本,longText和blob。我还尝试在其他表格中插入191个字符的字符串,并且还限制为191个字符。
我知道UTF8MB4会导致Varchar(255)实际为191,但是我不应该用Varchar(1000)覆盖它吗?数据库中是否有可能引起此问题的设置?
I am using MySQL 8.0 and I am trying to store a URL in a column. Every time I try to insert a URL longer than 191 characters, I get the following error:
1406 Data too long for column 'url' at row 1
The column data type is VARCHAR(1000) and the URL is ~450 characters. I have tried inserting other strings and anything 191 characters and under works fine but nothing does over 191 chars.
I have tried changing the datatype for this column to other string formats like TEXT, LONGTEXT, and BLOB. I have also tried inserting strings over 191 characters in other tables and they are also limited to 191 characters.
I know utf8mb4 causes VARCHAR(255) to actually be 191 but I shouldn't it be possible to override that with VARCHAR(1000)? Is there a setting in the database that can cause this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
取自 eshere :
因此,您最好使用
text
格式为您的URL。更新:
根据此答案,问题是在Charset中,是
utf8mb4
为utf8
,整理相同。Taken from here:
So you better to use
TEXT
format for your URLs.UPDATED:
According to this answer, the problem is in charset, which is
utf8mb4
when it needs to beutf8
, same for collation.