4

I have tried to use the export option in phpMyAdmin routines panel to copy functions from one database to another, with no success.

The export option supplies me with the following:

CREATE DEFINER=`root`@`localhost` FUNCTION `JSON_FIELD_NUM`(`col_name` TEXT CHARSET utf8, `data` TEXT CHARSET utf8) RETURNS text CHARSET utf8
    NO SQL
BEGIN
   RETURN 
   CONCAT('"',col_name,'":',
       IF(ISNULL(data),0,data)
   );
END

I get this error when I run that in another database:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 7 

I tried adding DELIMITER $$ at the top and $$ after END, but still no joy.

2 Answers 2

4

You must set your client's statement delimiter to a string other than ; in order that it doesn't think the semicolon which ends the CONCAT() expression also terminates the CREATE FUNCTION statement.

In the MySQL command line tool, you can use the DELIMITER command. In phpMyAdmin, you will need to use the Delimiter text box before clicking Go.

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

1 Comment

Delimiter text box ... so obvious once you know its there, Thanks
1

There is a far more concise way to do this:

MYSQLDUMP_OPTIONS="${MYSQLDUMP_OPTIONS} --routines"
MYSQLDUMP_OPTIONS="${MYSQLDUMP_OPTIONS} --all-databases"
MYSQLDUMP_OPTIONS="${MYSQLDUMP_OPTIONS} --no-data"
MYSQLDUMP_OPTIONS="${MYSQLDUMP_OPTIONS} --no-create-info"
mysqldump ${MYSQLDUMP_OPTIONS} > StoredProcedures.sql
less StoredProcedures.sql

This will dump only Stored Procedures.

Give it a Try !!!

3 Comments

Surely this will produce the same CREATE FUNCTION statement as that with which the OP is already having problems?
@eggyal The DELIMITER statements are generated within the mysqldump
And the OP says he's already tried using DELIMITER. The problem is that he's not using the MySQL command line tool.

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.