Can I run an HTTP GET directly in SQL under MySQL?

耗尽温柔 提交于 2019-12-20 04:37:15

问题


I'd love to do this:

UPDATE table SET blobCol = HTTPGET(urlCol) WHERE whatever LIMIT n;

Is there code available to do this? I known this should be possible as the MySQL Docs include an example of adding a function that does a DNS lookup.

MySQL / windows / Preferably without having to compile stuff, but I can.

(If you haven't heard of anything like this but you would expect that you would have if it did exist, A "proly not" would be nice.)

EDIT: I known this would open a whole can-o-worms re security, however in my cases, the only access to the DB is via the mysql console app. Its is not a world accessible system. It is not a web back end. It is only a local data logging system


回答1:


No, thank goodness — it would be a security horror. Every SQL injection hole in an application could be leveraged to start spamming connections to attack other sites.

You could, I suppose, write it in C and compile it as a UDF. But I don't think it really gets you anything in comparison to just SELECTing in your application layer and looping over the results doing HTTP GETs and UPDATEing. If we're talking about making HTTP connections, the extra efficiency of doing it in the database layer will be completely dwarfed by the network delays anyway.




回答2:


I don't know of any function like that as part of MySQL. Are you just trying to retreive HTML data from many URLs?

An alternative solution might be to use Google spreadsheet's importHtml function.

Google Spreadsheets Lets You Import Online Data




回答3:


Proly not. Best practises in a web-enviroment is to have database-servers isolated from the outside, both ways, meaning that the db-server wouldn't be allowed to fetch stuff from the internet.




回答4:


Proly not.

If you're absolutely determined to get web content from within an SQL environ, there are as far as I know two possibilities:

  1. Write a custom MySQL UDF in C (as bobince mentioned). The could potentially be a huge job, depending on your experience of C, how much security you want, how complete you want the UDF to be: eg. Just GET requests? How about POST? HEAD? etc.

  2. Use a different database which can do this. If you're happy with SQL you could probably do this with PostgreSQL and one of the snap-in languages such as Python or PHP.

If you're not too fussed about sticking with SQL you could use something like eXist. You can do this type of thing relatively easily with XQuery, and would benefit from being able to easily modify the results to fit your schema (rather than just lumping it into a blob field) or store the page "as is" as an xhtml doc in the DB.

Then you can run queries very quickly across all documents to, for instance, get all the links or quotes or whatever. You could even apply XSL to such a result with very little extra work. Great if you're storing the pages for reference and want to adapt the results into a personal "intranet"-style app.

Also since eXist is document-centric it has lots of great methods for fuzzy-text searching, near-word searching, and has a great full-text index (much better than MySQL's). Perfect if you're after doing some data-mining on the content, eg: find me all documents where a word like "burger" within 50 words of "hotdog" where the word isn't in a UL list. Try doing that native in MySQL!

As an aside, and with no malice intended; I often wonder why eXist is over-looked when people build CMSs. Its a database that can store content in its native format (XML, or its subset (x)HTML), query it with ease in its native format, and can translate it from its native format with a powerful templating language which looks and acts like its native format. Sometimes SQL is just plain wrong for the job!

Sorry. Didn't mean to waffle! :-$



来源:https://stackoverflow.com/questions/291673/can-i-run-an-http-get-directly-in-sql-under-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!