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

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值