ERROR 1813 (HY000) at line 404: Tablespace for table '`xxx`.`xxxxx`' exists.

╰+哭是因爲堅強的太久メ 2022-05-24 04:54 264阅读 0赞









1


2



今天在进行mysql备份实验时,通过mysqldump命令将主机host1中的所有数据库备份到主机Host2中,


在执行命令时出现了如下错误信息。










1


2


3


4


5



[root@localhost tmp]# mysqldump -h 192.168.5.22 -u root 
—password=1234 —all-databases|


 
mysql -h 192.168.5.33 -uroot 
—password=1234


ERROR 1813 (HY000) 
at 
line 404: Tablespace 
for 
table 
mysql.innodb_index_stats 
exists. 


Please DISCARD the tablespace before IMPORT.


mysqldump: Got errno 32 
on 
write

这个错误是说数据库mysql.innodb_index_stats 的表空间已经存在,在导入数据之前需要将这个表空间释放到。根据提示,进入到主机Host2中数据库存放目录中手工删除这些文件,操作如下:










1


2


3


4


5


6


7


8


9


10


11


12


13


14


15


16


17


18


19


20


21


22


23


24


25


26


27



[root@localhost ~]# cd /var/lib/mysql/mysql


[root@localhost mysql]# ls


columns_priv.frm   help_relation.frm       procs_priv.frm            time_zone.frm


columns_priv.MYD   help_relation.MYD       procs_priv.MYD            time_zone_leap_second.frm


columns_priv.MYI   help_relation.MYI       procs_priv.MYI            time_zone_leap_second.MYD


db.frm             help_topic.frm          proxies_priv.frm          time_zone_leap_second.MYI


db.MYD             help_topic.MYD          proxies_priv.MYD          time_zone.MYD


db.MYI             help_topic.MYI          proxies_priv.MYI          time_zone.MYI


event.frm          host.frm                servers.frm               time_zone_name.frm


event.MYD          host.MYD                servers.MYD               time_zone_name.MYD


event.MYI          host.MYI                servers.MYI               time_zone_name.MYI


func.frm           innodb_index_stats.ibd  slave_master_info.frm     time_zone_transition.frm


func.MYD           innodb_table_stats.frm  slave_master_info.ibd     time_zone_transition.MYD


func.MYI           innodb_table_stats.ibd  slave_relay_log_info.frm  time_zone_transition.MYI


general_log.CSM    ndb_binlog_index.frm    slave_relay_log_info.ibd  time_zone_transition_type.frm


general_log.CSV    ndb_binlog_index.MYD    slave_worker_info.frm     time_zone_transition_type.MYD


general_log.frm    ndb_binlog_index.MYI    slave_worker_info.ibd     time_zone_transition_type.MYI


help_category.frm  plugin.frm              slow_log.CSM              
user
.frm


help_category.MYD  plugin.MYD              slow_log.CSV              
user
.MYD


help_category.MYI  plugin.MYI              slow_log.frm              
user
.MYI


help_keyword.frm   proc.frm                tables_priv.frm


help_keyword.MYD   proc.MYD                tables_priv.MYD


help_keyword.MYI   proc.MYI                tables_priv.MYI


[root@localhost mysql]# mv innodb_index_stats.ibd  /tmp #这里将文件剪切到/tmp目录中去


[root@localhost mysql]# service mysql restart


Shutting down MySQL..                                      [  OK  ]


Starting MySQL.                                            [  OK  ]

重启完成后,进入主机Host1中再次执行备份命令,这时又出现了以下错误:










1


2


3


4



[root@localhost tmp]# mysqldump -h 192.168.5.22 -u root 
—password=1234 —all-databases|mysql -h 192.168.5.33 -uroot —password=1234


Warning: Using a 
password 
on 
the command line interface can be insecure.


Warning: Using a 
password 
on 
the command line interface can be insecure.


ERROR 1813 (HY000) 
at 
line 434: Tablespace 
for 
table 
mysql.innodb_table_stats 
exists. Please DISCARD the tablespace before IMPORT.

于是再次进入Host2中,删除innodb_table_stats文件,删除之后再次重启mysql服务器










1


2


3


4



[root@localhost mysql]# mv innodb_table_stats.ibd  /tmp


[root@localhost mysql]# service mysql restart


Shutting down MySQL..                                      [  OK  ]


Starting MySQL.                                            [  OK  ]

之后,再次进入Host1中执行备份命令,又会出现新的表错误信息,在Host2中执行同样的操作,依次删除文件slave_master_info、slave_relay_log_info、slave_worker_info后,直至不在出现错误信息,主机host1中的数据库全部复制到主机Host2中。










1


2


3


4


5


6


7


8


9


10


11


12


13


14


15


16


17


18


19


20


21


22


23


24


25


26


27


28


29


30


31


32


33


34


35


36



## 主机Host1执行的操作


[root@localhost tmp]# mysqldump -h 192.168.5.22 -u root 
—password=1234 —all-databases|mysql -h 192.168.5.33 -uroot —password=1234


Warning: Using a 
password 
on 
the command line interface can be insecure.


Warning: Using a 
password 
on 
the command line interface can be insecure.


ERROR 1813 (HY000) 
at 
line 647: Tablespace 
for 
table 
mysql.slave_master_info 
exists. Please DISCARD the tablespace before IMPORT.


[root@localhost tmp]# mysqldump -h 192.168.5.22 -u root 
—password=1234 —all-databases|mysql -h 192.168.5.33 -uroot —password=1234


Warning: Using a 
password 
on 
the command line interface can be insecure.


Warning: Using a 
password 
on 
the command line interface can be insecure.


ERROR 1813 (HY000) 
at 
line 691: Tablespace 
for 
table 
mysql.slave_relay_log_info 
exists. Please DISCARD the tablespace before IMPORT.


[root@localhost tmp]# mysqldump -h 192.168.5.22 -u root 
—password=1234 —all-databases|mysql -h 192.168.5.33 -uroot —password=1234


Warning: Using a 
password 
on 
the command line interface can be insecure.


Warning: Using a 
password 
on 
the command line interface can be insecure.


ERROR 1813 (HY000) 
at 
line 720: Tablespace 
for 
table 
mysql.slave_worker_info 
exists. Please DISCARD the tablespace before IMPORT.


[root@localhost tmp]# mysqldump -h 192.168.5.22 -u root 
—password=1234 —all-databases|mysql -h 192.168.5.33 -uroot —password=1234


Warning: Using a 
password 
on 
the command line interface can be insecure.


Warning: Using a 
password 
on 
the command line interface can be insecure.


[root@localhost tmp]# 


 


## 主机Host2中执行的操作


 


[root@localhost mysql]# mv innodb_table_stats.ibd  /tmp


[root@localhost mysql]# service mysql restart


Shutting down MySQL..                                      [  OK  ]


Starting MySQL.                                            [  OK  ]


[root@localhost mysql]# mv slave_master_info.ibd /tmp


[root@localhost mysql]# service mysql restart


Shutting down MySQL..                                      [  OK  ]


Starting MySQL.                                            [  OK  ]


[root@localhost mysql]# mv slave_relay_log_info.ibd /tmp


[root@localhost mysql]# service mysql restart


Shutting down MySQL..                                      [  OK  ]


Starting MySQL.                                            [  OK  ]


[root@localhost mysql]# mv slave_worker_info.ibd /tmp


[root@localhost mysql]# service mysql restart


Shutting down MySQL..                                      [  OK  ]


Starting MySQL.                                            [  OK  ]

解决流程如下:

  1. 1、关闭所有mysql操作,停止mysql服务。
  2. 2、找到安装目录下的数据库文件,应该在你安装目录下的data文件夹下,然后打开你对应的数据库名的文件夹。找到那个表对应的文件,将其删除。数据库中的文件名,应该是和你的表名一一对应的,一个表,两个文件,一个数据文件,一个是日志文件,除了这个还有一个“db.opt”文件不要删除。其他的乱码的文件,和原来你出错的文件全部删除。
  3. 3、完了以后重新启动mysql服务,重新添加那个同样名字的表就可以添加成功了。

发表评论

表情:
评论列表 (有 0 条评论,264人围观)

还没有评论,来说两句吧...

相关阅读