3

I am trying to use pymysql to create a stored procedure in mysql database. I have a file which contains the statements to create stored procedure. I am running the mysql queries line by line using cursor.execure(line). The Queries to create stored procedure runs fine on the db. But on python they are giving syntax error.

DELIMITER $$

USE `ipaybridge2`$$

DROP PROCEDURE IF EXISTS `masking`$$

CREATE DEFINER=`root`@`%` PROCEDURE `masking`()
BEGIN
 
 query statements;

END$$

DELIMITER ;

the error i get is this: You have an error in your SQL syntax; it seems the error is around: 'DELIMITER $ $ USE `ipaybridge2` $ $ DROP PROCEDURE IF EXISTS `masking` $ $ CREAT' at line 1

1 Answer 1

3

pymsysql does not want the DELIMITER statements. So you should already be connected to a specific database and thus the USE statement should not be required. Just pass the following to cursor.execute as a separate command:

DROP PROCEDURE IF EXISTS `masking`

And then pass to cursor.execute as the next command:

CREATE DEFINER=`root`@`%` PROCEDURE `masking`()
BEGIN
 
 query statements;

END

See Error when trying to create stored procedure

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.