Can't create a table in MySQL because "it already exists" - mysql

I am having an issue with MySQL, relating to my previous question.
I recently needed to remove a table from MySQL, and now need to create a new one in its place. I am having a hard time with this because, as MySQL Workbench says, "The table already exists." Since the error from MySQL Workbench is not particularly helpful, here's some stuff that I pulled out of my error log. What's the problem?
I am running MySQL 5.7 on Windows 8.1 Pro x64.
2014-03-06T01:38:55.459658Z 0 [ERROR] InnoDB: Table thepwf_prgminteractions/p2p_messagedata in the InnoDB data dictionary has tablespace id 25, but tablespace with that id or name does not exist. Have you deleted or moved .ibd files? This may also be a table created with CREATE TEMPORARY TABLE whose .ibd and .frm files MySQL automatically removed, but the table still exists in the InnoDB internal data dictionary.
InnoDB: Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting-datadict.html
InnoDB: for how to resolve the issue.
2014-03-06T01:38:55.464671Z 0 [ERROR] InnoDB: Table thepwf_prgminteractions/p2p_onlineusers in the InnoDB data dictionary has tablespace id 26, but tablespace with that id or name does not exist. Have you deleted or moved .ibd files? This may also be a table created with CREATE TEMPORARY TABLE whose .ibd and .frm files MySQL automatically removed, but the table still exists in the InnoDB internal data dictionary.
InnoDB: Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.7/en/innodb-troubleshooting-datadict.html
InnoDB: for how to resolve the issue.
2014-03-06T01:38:55.468672Z 0 [ERROR] InnoDB: Table thepwf_prgminteractions/p2pchat_betaaccesskeys in the InnoDB data dictionary has tablespace id 24, but tablespace with that id or name does not exist. Have you deleted or moved .ibd files? This may also be a table created with CREATE TEMPORARY TABLE whose .ibd and .frm files MySQL automatically removed, but the table still exists in the InnoDB internal data dictionary.

As the table exists then just remove it with drop table (http://dev.mysql.com/doc/refman/5.6/en/drop-table.html)
i.e.
drop table <table name>
You must have done something wrong as the table still exists.
Can check this with select
i.e.
select * from <table name>

It looks your innodb tablespace has been corrupted.
Checkout this post from percona
http://www.mysqlperformanceblog.com/2008/07/04/recovering-innodb-table-corruption/
And these tools
http://www.percona.com/software/percona-toolkit
They will save you!
Well I don't know how well they run on windows but what the tools do should be about the same.

Go to where your mysql folder is installed:
C:\Apps\mysql-5.6.25-win64\data\databasename
Under databasename you will find your tablename. Delete this table manually and create it again using SQL Create Table command.

Related

DataBase Error InnoDB: cannot calculate statistics for table

While checking the error logs in my wordpress site I would get the following for the mysql logs.
161120 6:41:58 InnoDB: cannot calculate statistics for table databasename/wp_wfHoover
InnoDB: because the .ibd file is missing. For help, please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.5/en/innodb-troubleshooting.html
161120 6:41:58 [ERROR] MySQL is trying to open a table handle but the .ibd file for
table databasename/wp_wfHoover does not exist.
Have you deleted the .ibd file from the database directory under
the MySQL datadir, or have you used DISCARD TABLESPACE?
See http://dev.mysql.com/doc/refman/5.5/en/innodb-troubleshooting.html
What is the problem here? My site is hosted on an ubuntu server using apache2.Thanks in advance

MySQL 5.6 Innodb running out single-table tablespace id's

I am looking for general information regarding this message:
InnoDB: Warning: you are running out of new single-table tablespace id's.
InnoDB: Current counter is 2152000000 and it must not exceed 4294967280!
InnoDB: To reset the counter to zero you have to dump all your tables and
InnoDB: recreate the whole InnoDB installation.
Which counter? How do you query it? Does an entire restore fix this problem?
From Percona Support:
When you create one table in innodb, that counter will be increased by 1.
This table id seems to be a 32bit value.
In my case, we created lots of temporary tables. On MySQL 5.6 default engine for temporary tables is innodb hence the problem. Once I changed it to MYISAM the warnings disappeared.

How to restore Innodb database?

I physically moved the database and now I am not able to restore Innodb database.
I am getting this error-
140131 13:03:41 [ERROR] Cannot find or open table table_t1/t1#P#p0 from
the internal data dictionary of InnoDB though the .frm file for the
table exists. Maybe you have deleted and recreated InnoDB data
files but have forgotten to delete the corresponding .frm files
of InnoDB tables, or you have moved .frm files to another database?
or, the table contains indexes that this version of the engine
doesn't support.
See http://dev.mysql.com/doc/refman/5.5/en/innodb-troubleshooting.html
how you can resolve the problem.
Help me to restore this db
Put it back and move it through the SQL interface (e.g. RENAME TABLE).

table is in the system tablespace 0 which cannot be discarded

I am trying to run this query:
alter table about_member discard tablespace;
But when I do, my error logs are outputting this:
InnoDB: Error: table `diskise`.`about_member`
InnoDB: is in the system tablespace 0 which cannot be discarded
What can I do so I can discard this tablespace so I can import a backup that I have?
See this manual page:
By default, all InnoDB tables and indexes are stored in the system tablespace. As an alternative, you can store each InnoDB table and its indexes in its own file. This feature is called “multiple tablespaces” because each table that is created when this setting is in effect has its own tablespace.
Advantages of Per-Table Tablespaces
You can reclaim disk space when truncating or dropping a table. For tables created when file-per-table mode is turned off, truncating or dropping them creates free space internally in the ibdata files. That free space can only be used for new InnoDB data.
It sounds like you created your table in the default tablespace, so you cannot discard the tablespace. That said, you should be able to import data without discarding a tablespace first, unless you're just out of disk space.
I just ran into same problem while I was trying to restore one table from .ibd file. I know it's been a long time so I wrote this here for people who still running into the same problem.
Continuing with #Ed Cottrell's answer, you will need to change the mysql global variable innodb_file_per_table to let mysql to store .ibd in your own file instead of using system tablespace.
To achieve this you can do (also see official docs):
change your my.cnf file, adding following line and restart mysql server
[mysqld]
innodb_file_per_table=1
set global variable in mysql command (sometimes not working due to security issue)
SET GLOBAL innodb_file_per_table=1;
You may need to DROP your table before this take effects.
After doing this, you will be able to see .ibd files inside PATH/TO/MYSQL/DB_NAME directory (e.g. /var/lib/mysql/DB_NAME).

Mysql InnoDB Error code #1025

We are using Mysql 5.1 in our production servers and trying to run an alter query to change the datatype of a column from tinytext to varchar(200). On running the alter query we are seeing this error :-
#1025 - Error on rename of './msging/#sql-123b_ab7634' to
'./msging/outboxes' (errno: -1)
The MySql forums suggest that this error might be because of foreign key constraints. But our schema does not have any foreign keys. The mysql error logs are showing the below mentioned error.We went through the link mentioned in the error statement but couldn't find anything useful. Any ideas what might be going wrong ?
InnoDB: Error: './msging/outboxes.ibd' is already in tablespace memory
cache 111001 12:40:18 InnoDB: Error in table rename, cannot
rename msging.#sql-123b_ab4828 to msging.outboxes 111001
12:40:18 InnoDB: Error: table msging.outboxes does not exist in
the InnoDB internal InnoDB: data dictionary though MySQL is
trying to drop it. InnoDB: Have you copied the .frm file of the
table to the InnoDB: MySQL database directory from another
database? InnoDB: You can look for further help from InnoDB:
http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting.html
When you rename a table using ALTER TABLE, here's what happens:
The table is copied to a new file with a random filename.
Changes are made to the new file.
The old table is renamed using a random temporary filename.
The new table is renamed to take the place of the old file.
The old table is removed.
See this link for more details: http://www.xaprb.com/blog/2006/08/22/mysqls-error-1025-explained/
You can use innotop to get more details on the error: http://code.google.com/p/innotop/