问题
I want to call rest api in a POST
method from a stored procedure or trigger in mysql server on windows.
How do I perform this solely with MySQL?
回答1:
You can use a mysql-udf-http and then create a trigger like this:
delimiter $$
CREATE TRIGGER upd_check BEFORE UPDATE ON account
FOR EACH ROW
BEGIN
IF NEW.amount > 0 THEN
set @json = select json_object(account_id,amount)
select http_post('http://restservice.example.com/account/post',@json);
END IF;
END;$$
delimiter;
回答2:
Basically you can't. And if you could (thru the use of a UDF library) you shouldn't.
Mysql is a high performance db engine that you ought to respect for its core competencies. Other stakeholders and waiting for your query or transaction to wrap up, and they suffer while yours doesn't. It is not a webserver with callbacks from asynchronous calls. Triggers and stored procs need to get in and get out as they are often used in a Transactional setting.
来源:https://stackoverflow.com/questions/40470267/calling-a-rest-api-from-a-trigger-or-stored-procedure-in-mysql