8

Because of loadshading issue, one of the table in my database got currupted. I dropped the table and now I want to create the table again.

I'm getting this error:

ERROR 1813: Tablespace for table 'zorkif.sys_user_accounts' exists. Please DISCARD the tablespace before IMPORT.

SQL Statement:

CREATE TABLE `zorkif`.`sys_user_accounts` ( `UserID` INT NOT NULL AUTO_INCREMENT , PRIMARY KEY (`UserID`) , UNIQUE INDEX `UserID_UNIQUE` (`UserID` ASC) ) 

What is tablespace and how to discard this tablespace? Is there any command I have to run in query? How to deal with this issue?

4

12 Answers 12

13

This works for me, but I use this in local server.

Open the directory where xampp is installed, for example

C:/xampp/mysql/data/... 

Select the folder (it's like a database name) of the tablespace that you want to remove, then delete the file with extension idb. Delete only one file corresponding to the table that you want to create/remove.

In my case my file is karyawan.idb,

Hope this works for you.

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

1 Comment

this also resolve my issue but it is not good approach follow this : dev.mysql.com/doc/refman/8.0/en/drop-tablespace.html
5

It took me quite a while to fix this issue on one of my production dbs. The following steps actually solved the problem pretty cleanly:

-> deactivate your app/page - any requests to your db (if you dont have a service mode in your app - build one :P) -> mysqldump your db (optionally with --routines=true); -> kill the folder with db name -> create schema db name; -> drop schema db name; -> restart mysql (service mysql restart - or similar depending on your os) -> create schema db name; -> mysql import your previously created dump; 

1 Comment

thanks man, this actually helped repair my local xampp with such a defect still existing database.
4

Duplicate Error: Tablespace for table xxx exists. Please DISCARD the tablespace before IMPORT

<WAMP or XAMPP path >\bin\mysql\mysqlX.X.XX\data\<your database name> 

Remove your whole database folder & restart apache.

Create your database again & import database.

It works.

Comments

2

Step 1: Backup mysql/database/*.ibd to another folder

Step 2: Delete all mysql ib_logfile*

Step 3: Restart mysql service

Step 4: Login into mysql from shell

Step 5: Run:

- use database; - ALTER TABLE table_name DISCARD TABLESPACE; 

(Repeat for all tables that has problem with tablespace)

Step 6: Copy *.ibd from backup folder to mysql/database/ folder

Step 7: Repeat step 3,4 with running query:

- use database; - ALTER TABLE table_name IMPORT TABLESPACE; 

1 Comment

Mysql service won't start 😔 What to do?
1

Trying to drop the tablespace can give you other errors. For me, I got the following error:

DROP TABLESPACE `tablename` Error Code: 1478. Table storage engine 'InnoDB' does not support the create option 'TABLESPACE or LOGFILE GROUP' 

My solution was to drop the database. This will remove any tablespaces related to it and allow you to create the tables again.

Comments

1

The following works on MariaDB 10.3.12:

  • create another table with the same name in another database
  • sudo cp -p otherdb/tablename.frm problemdb/tablename.frm
  • drop table problemdb.tablename

Everything should work and be clean after this.

Comments

1

Open the directory where MAMP is installed, for example

Macintosh⁩ ▸ ⁨Applications⁩ ▸ ⁨MAMP⁩ ▸ ⁨db⁩ ▸ ... Select the folder (it's like a database name) of the tablespace that you want to remove, then delete the file with extension idb. Delete only one file corresponding to the table that you want to create/remove.

For Example file : ‎⁨Macintosh⁩ ▸ ⁨Applications⁩ ▸ ⁨MAMP⁩ ▸ ⁨db⁩ ▸ ⁨mysql57⁩ ▸ ⁨example_db ▸ amc_customer.ibd

Try this. It's work for me.

Comments

1

In my case even after I deleted table before Import, I could not discard TABLESPACE because mysql was saying that no TABLESPACE exists, if that's the case it's because indexes of that table remains so you need to delete those indexes

DELETE FROM innodb_index_stats WHERE table_name='table_name_here'; 

After that Discard tablespace error is not occurred anymore and I could successfully import table

Comments

0

Before creating this table run this query for removing the TABLESPACE

DROP TABLESPACE `zorkif`.`sys_user_accounts` TABLESPACE can contain one or more data files, providing storage space for tables. 

1 Comment

Error Code: 1478. Table storage engine 'InnoDB' does not support the create option 'TABLESPACE or LOGFILE GROUP'
0

Steps to resolve this matter:

  1. export your schema to backup file
  2. drop schema
  3. modify your SQL script exported, adding the 'create table' you need
  4. create the same schema
  5. import your schema from backup file

Comments

0

if you encounter this error on your local host, just go to the xamp folder, move to mysql folder, move to data folder, inside the data folder you will see the list of database based on the database name, select the folder of the database that is giving you error, the the particular table name that is give you the error and re-import your database.

Just solve this on my system now

Comments

0

If you're on a Mac, go to Applications->XAMPP->xamppfiles->var-mysql look for your database name. You might have to give 'read&write' access to 'everyone' in privileges. Thereafter, delete the relevant .idb file. Restart XAMPP and you should be good to go.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.