简体   繁体   中英

how to export and import stored procedures from phpmyadmin

Can you guys help me out regarding stored procedures. When I export stored procedure from phpmyadmin, It given as

CREATE DEFINER=`root`@`localhost` PROCEDURE `c4mo_get_cities_prc`(IN `p_state_code` VARCHAR(3), IN `p_country_code` VARCHAR(3), IN `p_language_code` VARCHAR(3))
    NO SQL
BEGIN

SELECT city_name, city_code
FROM `c4mo_cities` 
WHERE enabled = 'Y' 
AND language_code = p_language_code
AND state_code = p_state_code
AND country_code = p_country_code;

END

And when I import it from phpmyadmin, it giving error as

#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 13 

Copy the exported stored procedure to file eg myprocedure.sql. Now modify that .sql file with following: 1) Remove DEFINER= root @ localhost 2) At the beginning of stored procedure add delimiter definition. and at the end reset delimiter.

eg

`DELIMITER $$
`CREATE  PROCEDURE `c4mo_get_cities_prc`(IN `p_state_code` VARCHAR(3), IN 
`p_country_code` VARCHAR(3), IN `p_language_code` VARCHAR(3))
NO SQL
BEGIN

SELECT city_name, city_code
FROM `c4mo_cities` 
WHERE enabled = 'Y' 
AND language_code = p_language_code
AND state_code = p_state_code
AND country_code = p_country_code;

END $$
DELIMITER ;

After that import stored procedure just like any other database you import by selecting .sql file.

Thank you

Remove DEFINER= root @ localhost

in local while import,

it will execute.

It quite simple if you use phpmyadmin interface.

For export :

You will see a routine tab as this tab will be shown only when you will already have at least one stored procedure.

Just Click on routines tab and you will see your made stored procedure(For the db , you have made).

At below, tick check all on check Box and then export , You just need to copy the whole code and save it to anywhere on your local machine with your_stored_procedure.sql file.

For import:

Just select the database and import your stored procedure your_stored_procedure.sql file as mentioned above, as you generally import .sql file(tables) for your db.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM