URL length varies, how does MySQL store it?
Because I need the URL as a unique index to use, later used as a query, short index I think the meaning is not very significant.
Is there a good way to turn long strings into short strings or numbers to store them (or otherwise), or is it a bad choice to use the MySQL store itself?
Reply content:
URL length varies, how does MySQL store it?
Because I need the URL as a unique index to use, later used as a query, short index I think the meaning is not very significant.
Is there a good way to turn long strings into short strings or numbers to store them (or otherwise), or is it a bad choice to use the MySQL store itself?
URLs do not have to be indexed, string index Some aspects if not good will be very slow, not to mention you are the URL.
If you still want URL storage and URL is very long, and want to shorten the string can use the short domain API interface, to shorten the URL
The access effect is the same.
原网址: http://music.baidu.com/song/124380645短网址: http://dwz.cn/Kn8Ep
No matter how long the URL will be shortened to a fixed length.
Baidu short URL (page with API): http://dwz.cn/
Short URL processing is good, save capacity, but it is recommended to store a short URL at the same time save a copy of the original URL,
The URL string you use as a unique index is a bad scenario.
You can try to maintain a key-value table, and then write the key to the field you need to guarantee the unique, field with int or bigint, plus a unique index
Add one more field url_md5 the value of the MD5 (URL) to this field, and set a unique index for the Url_md5 field. When querying, the URL to be queried takes md5:select * from table_name where URL_MD5=URL_MD5.
The point to note in this way is that the URL may be different, but the MD5 (URL) is the same, which only needs to be judged by whether the URL in the data table Recordset is the same as the URL you need.