当我有一个表在日志文件中显示完全相同的错误时,这正是我在fedora的mariadb 10.2.16中所做的...
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
您的里程和错误可能会有所不同,但我认为主要是
...already exists though the corresponding table did not exist in the InnoDB data dictionary...
与删除表不起作用以及更改表...
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' doesn't exist
创建表也将失败,如下所示:
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
为了解决这个问题,我首先要做的是
create table innodb_table2(`id` int(10) unsigned NOT NULL);
Query OK, 0 rows affected (0.07 sec)
然后在/ var / lib / mysql / database_name目录中,我以root身份执行以下操作,以确认innodb_table.ibd的覆盖导致了我们的问题
cp -a innodb_table2.frm innodb_table.frm
cp -a innodb_table2.ibd innodb_table.ibd
systemctl restart mariadb
然后回到mysql控制台,我在两个表上都发出了成功的drop命令
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)
现在一切都变成正方形了,我可以重新创建一张桌子...
MariaDB [database_name]> create table innodb_table (`id` int(10) unsigned NOT NULL);
Query OK, 0 rows affected (0.08 sec)
编辑:我要添加一个
restorecon -Rv /var/lib/mysql/database_name
复制数据库后的命令以按其应有的方式获取所有selinux上下文,即使我们几乎立即将它们从数据库中删除,但也可以将--archive或-a选项添加到两个cp中命令,所以实际上是archive选项可以缩短此操作:
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
我认为更好的是以下内容,它保留为已制成的表设置的selinux上下文。
cp -a innodb_table2.frm innodb_table.frm
cp -a innodb_table2.ibd innodb_table.ibd
systemctl restart mariadb
我已将上述较长的命令列表替换为较短的命令列表,可以将其缩短为*