This is exactly what I did in mariadb 10.2.16 on fedora, when I had a table that showed the same errors in the log file, I suppose ...
2018-07-11 9:43:58 140323764213504 [Note] InnoDB: The file './database_name/innodb_table.ibd' already exists though the corresponding table did not exist in the InnoDB data dictionary. You can resolve the problem by removing the file. 2018-07-11 9:44:29 140323764213504 [Warning] InnoDB: Tablespace 'database_name/innodb_table' exists in the cache with id 2836 != 2918
mileage and errors may vary, but I assume that the main one is
...already exists though the corresponding table did not exist in the InnoDB data dictionary...
working with a delete table does not work as well as changing a table ...
MariaDB [database_name]> drop table innodb_table; ERROR 1051 (42S02): Unknown table 'database_name.innodb_table' MariaDB [database_name]> alter table innodb_table discard tablespace; ERROR 1146 (42S02): Table 'database_name.innodb_table' does not exist
creating a table also fails like this:
MariaDB [database_name]> create table innodb_table('id' int(10) unsigned NOT NULL); ERROR 1813 (HY000): Tablespace for table ''database_name'.'innodb_table'' exists. Please DISCARD the tablespace before IMPORT
To fix this, first I did
create table innodb_table2('id' int(10) unsigned NOT NULL); Query OK, 0 rows affected (0.07 sec)
then in the directory / var / lib / mysql / database_name I did the following as a root user, confirming the rewrite of innodb_table.ibd, which caused us problems
cp -a innodb_table2.frm innodb_table.frm cp -a innodb_table2.ibd innodb_table.ibd systemctl restart mariadb
then in mysql console I executed a successful delete command for both tables
MariaDB [database_name]> drop table innodb_table; ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 8 Current database: database_name Query OK, 0 rows affected (0.08 sec) MariaDB [database_name]> drop table innodb_table2; Query OK, 0 rows affected (0.25 sec)
and now all the squares, and I can recreate one table ...
MariaDB [database_name]> create table innodb_table ('id' int(10) unsigned NOT NULL); Query OK, 0 rows affected (0.08 sec)
UPDATE: I was going to add in
restorecon -Rv /var/lib/mysql/database_name
Teamafter copying the database to get all selinux contexts as they should be, even if we remove them from the database almost immediately, but as an alternative, you can simply add the --archive or -a option for the two cp commands, so yes, actually the archive option shortens this:
cp innodb_table2.frm innodb_table.frm cp innodb_table2.ibd innodb_table.ibd chown mysql:mysql innodb_table.frm innodb_table.ibd chmod 660 innodb_table.frm innodb_table.ibd restorecon -Rv /var/lib/mysql/database_name systemctl restart mariadb
to the next, which I think is better, and this preserves the Selinux context that is set for the already created table.
cp -a innodb_table2.frm innodb_table.frm cp -a innodb_table2.ibd innodb_table.ibd systemctl restart mariadb
I replaced the above long list of commands with a shorter list that can be shortened with *