Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got an ExpressionEngine database and I exported a couple of tables from it, then dropped those tables. When I try to re-import the tables in PHPMyAdmin, I get this error:

SQL query:

-- -- Database: `my_db` -- DELIMITER $$ -- -- Functions -- CREATE DEFINER=`my_username`@`%` FUNCTION `LEVENSHTEIN`(s1 VARCHAR(255), s2 VARCHAR(255)) RETURNS int(11) DETERMINISTIC BEGIN DECLARE s1_len, s2_len, i, j, c, c_temp, cost INT; DECLARE s1_char CHAR; DECLARE cv0, cv1 VARBINARY(256); SET s1_len = CHAR_LENGTH(s1), s2_len = CHAR_LENGTH(s2), cv1 = 0x00, j = 1, i = 1, c = 0; IF s1 = s2 THEN RETURN 0; ELSEIF s1_len = 0 THEN RETURN s2_len; ELSEIF s2_len = 0 THEN RETURN s1_len; ELSE WHILE j <= s2_len DO SET cv1 = CONCAT(cv1, UNHEX(HEX(j))), j = j + 1; END WHILE; WHILE i <= s1_len DO SET s1_char = SUBSTRING(s1, i, 1), c = i, cv0 = UNHEX(HEX(i)), j = 1; WHILE j <= s2_len DO SET c = c + 1; IF s1_char = SUBSTRING(s2, j, 1) THEN SET cost = 0; ELSE SET cost = 1; END IF; SET c_temp = CONV(HEX(SUBSTRING(cv1, j, 1)), 16, 10) + cost; IF c > c_temp THEN SET c = [...]

MySQL said: Documentation

#1304 - FUNCTION LEVENSHTEIN already exists 

I get this error even if I drop all tables from the DB and try to import anything. The only way I can get the error to go away is to totally delete the database and re-create it.

What's causing that error and how can I stop it from happening?

share|improve this question

migrated from Oct 23 '13 at 16:44

This question came from our site for system and network administrators.

I am a bit confused here. You say you are trying to re-import a sub-set of tables, so why are you trying to re-create that function? Adjust your backups so that you don't include the function create statement? Or drop the function in addition to the tables? – Zoredache Oct 22 '13 at 16:35
@Zoredache I know next to nothing about databases, so I don't even know what a "function" is in relation to a DB. All I know is I've done this kind of operation before without issue, which is why I'm asking about this. – kgrote Oct 22 '13 at 17:07

Check your import .sql script. There is possibly a create function statement between the create tables. You have dropped the tables, but the functions already exists because you didn't know it was there.

BTW if you would clear the tables, you must not drop an recreate them, you could also issue a truncate table tbl_name;

share|improve this answer

When exporting tables in PHPMyAdmin, use the "Custom" method. Under "Object Creation Options", uncheck the box that says "Add CREATE PROCEDURE / FUNCTION / EVENT statement".

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.