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?
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.
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.
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;
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;
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.
Solution
However, the easier option is this: restart mysql, then do the same four steps listed near the beginning of the post. This way, the tablespace id on the data dictionary and the file matched; thus importing the tablespace succeeded.
This can give you greater confidence in dealing with some of the InnoDB "gotcha's" during the recovery process or even file transfers.
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.
Steps to resolve this matter:
- export your schema to backup file
- drop schema
- modify your SQL script exported, adding the 'create table' you need
- create the same schema
- import your schema from backup file
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
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.
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.
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.
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
来源:https://stackoverflow.com/questions/16008782/what-is-and-how-to-remove-tablespace-error-from-my-database