MySQL – Why Does mysqldump Require DROP Command?

MySQLmysqldump

I am trying to backup a large table and after reading various other answers on this site have tried

mysqldump --user=user --password=password dbname1 tablename | mysql --user=user --password=password dbname2

I get the error

DROP command was denied to user 'user'@'localhost' for table tablename

which scares me. This is the first time I've worked with such a large DB and thus needed to use mysqldump, so I don't know what's going on. Why would it need the DROP command? I want to basically copy the table into another database, not modify (or delete) the existing one in any way.

Best Answer

By default mysqldump will output commands to drop tables, if they exist. This is why you get the error. It doesn't come from the mysqldump command, but from the mysql command you are piping the commands to. The user doesn't have permission to drop the table.

You can append --skip-add-drop-table to the mysqldump command to remove the DROP TABLE commands, but then you will get errors if the tables exist.

mysqldump parameters