URL的最佳数据库字段类型 [英] Best database field type for a URL

查看:1122
本文介绍了URL的最佳数据库字段类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在MySQL表中存储一个url。

I need to store a url in a MySQL table. What's the best practice for defining a field that will hold a URL with an undetermined length?

推荐答案


    最好的做法是定义一个字段,
  1. 常用网络浏览器中最低公分母的最大网址长度: 2,083 (Internet Explorer)

  1. Lowest common denominator max URL length among popular web browsers: 2,083 (Internet Explorer)

http://dev.mysql.com/doc/refman/5.0/en/char.html

VARCHAR列中的值是可变长度字符串。长度可以指定为MySQL 5.0.3之前的0到255之间的值,以及5.0.3和更高版本中的0到65,535。 MySQL 5.0.3及更高版本中VARCHAR的有效最大长度受最大行大小(65,535字节,所有列共享)和所使用的字符集的限制。

http://dev.mysql.com/doc/refman/5.0/en/char.html
Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions. The effective maximum length of a VARCHAR in MySQL 5.0.3 and later is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.

所以...

< MySQL 5.0.3使用 TEXT



> = MySQL 5.0.3使用 VARCHAR(2083) >

So ...
< MySQL 5.0.3 use TEXT
or
>= MySQL 5.0.3 use VARCHAR(2083)


这篇关于URL的最佳数据库字段类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆