Search code examples
mysqlrestore

MYSQL Error at restoring database: Please DISCARD the tablespace before IMPORT


For many times I have done successfully the same sequence for restoring the database commerce_db_622:

  1. Go to the directory /usr/local/mysql/data and perform the command:

    sudo rm -rf COMMERCE_DB_622.

This drops the database COMMERCE_DB_622

  1. Start the DB client :

     mysql –u root

  2. Run the following script to create the database:

    CREATE DATABASE COMMERCE_DB_622 /*!40100 DEFAULT CHARACTER SET utf8 */;
    
  3. Move to the directory that stores the dump file COMMERCE_DB_622.sql and run the following command:

    mysql -u root COMMERCE_DB_622 < COMMERCE_DB_622.sql

This worked fine but suddenly today I am starting getting the error with the valid already checked backup file.

ERROR 1813 (HY000) at line 25: Tablespace for table 'commerce_db_622.batch_job_execution' exists. Please DISCARD the tablespace before IMPORT.


Solution

  • I deleted the database using the following: cd data; sudo rm -rf COMMERCE_DB_622;

    However, the important thing is always in the beginning use the regular remove SQL: DROP DATABASE COMMERCE_DB_622

    If the "DROP DATABASE" SQL results in error then one can remove the data using the remove directory command.