当前位置:   article > 正文

k8s集群下mysql容器更换pvc存储迁移数据,报错InnoDB: Your database may be corrupt

k8s集群下mysql容器更换pvc存储迁移数据,报错InnoDB: Your database may be corrupt

一、背景:

在业务生产环境维护过程中会出现k8s集群下mysql容器需要更换pvc存储的场景,更换pvc存储就必须得做数据迁移,不然会出现业务数据丢失的情况。实施的方案主要有两种:

方案一:
1、将需要迁移的mysql容器里的数据通过mysqldump的方式导出来;
2、然后更换pvc存储,然后通过source 数据文件.sql的方式导入到新的数据库中;
方案二:

1、先新建pvc存储,然后挂载到mysql容器中的另一个目录上;
2、然后在容器里将mysql的数据复制到新的pvc存储挂载的目录上,修改权限和属主;

3、替换旧的pvc存储,然后mysql容器;

二、实施mysql容器数据迁移

这里主要选择是方案二的操作。

1、创建新的pvc存储:

 

2、在mysql容器上挂载新pvc存储:

 

这里是将新pvc存储挂载mysql容器的/mnt目录下,记得生效容器配置。 

3、登入到mysql容器里cp迁移数据:

 cd到mysql存放数据的目录,这里默认的是/var/lib/mysql的

  1. root@mysql-ozthj-b7b7cb9cd-m8hr4:/# cd /var/lib/mysql
  2. root@mysql-ozthj-b7b7cb9cd-m8hr4:/var/lib/mysql# ls
  3. auto.cnf ca.pem client-key.pem ib_logfile0 ibdata1 mysql private_key.pem server-cert.pem sys
  4. ca-key.pem client-cert.pem ib_buffer_pool ib_logfile1 ibtmp1 performance_schema public_key.pem server-key.pem xxl_job

然后通过cp命令将/var/lib/mysql目录下的所有数据复制到/mnt/目录下,并设置属主: 

  1. root@mysql-ozthj-b7b7cb9cd-m8hr4:/var/lib/mysql# ls
  2. auto.cnf ca.pem client-key.pem ib_logfile0 ibdata1 mysql private_key.pem server-cert.pem sys
  3. ca-key.pem client-cert.pem ib_buffer_pool ib_logfile1 ibtmp1 performance_schema public_key.pem server-key.pem xxl_job
  4. root@mysql-ozthj-b7b7cb9cd-m8hr4:/var/lib/mysql# cp -r * /mnt/
  5. root@mysql-ozthj-b7b7cb9cd-m8hr4:/var/lib/mysql# cd /mnt
  6. root@mysql-ozthj-b7b7cb9cd-m8hr4:/mnt# ls
  7. auto.cnf ca.pem client-key.pem ib_logfile0 ibdata1 lost+found performance_schema public_key.pem server-key.pem xxl_job
  8. ca-key.pem client-cert.pem ib_buffer_pool ib_logfile1 ibtmp1 mysql private_key.pem server-cert.pem sys
  9. root@mysql-ozthj-b7b7cb9cd-m8hr4:/mnt# chown -R mysql:mysql *
  10. root@mysql-ozthj-b7b7cb9cd-m8hr4:/mnt# ls -l
  11. total 188496
  12. -rw-r----- 1 mysql mysql 56 Jan 31 03:07 auto.cnf
  13. -rw------- 1 mysql mysql 1676 Jan 31 03:07 ca-key.pem
  14. -rw-r--r-- 1 mysql mysql 1112 Jan 31 03:07 ca.pem
  15. -rw-r--r-- 1 mysql mysql 1112 Jan 31 03:07 client-cert.pem
  16. -rw------- 1 mysql mysql 1680 Jan 31 03:07 client-key.pem
  17. -rw-r----- 1 mysql mysql 678 Jan 31 03:07 ib_buffer_pool
  18. -rw-r----- 1 mysql mysql 50331648 Jan 31 03:07 ib_logfile0
  19. -rw-r----- 1 mysql mysql 50331648 Jan 31 03:07 ib_logfile1
  20. -rw-r----- 1 mysql mysql 79691776 Jan 31 03:07 ibdata1
  21. -rw-r----- 1 mysql mysql 12582912 Jan 31 03:07 ibtmp1
  22. drwx------ 2 mysql mysql 16384 Jan 31 03:02 lost+found
  23. drwxr-x--- 2 mysql mysql 4096 Jan 31 03:07 mysql
  24. drwxr-x--- 2 mysql mysql 4096 Jan 31 03:07 performance_schema
  25. -rw------- 1 mysql mysql 1680 Jan 31 03:07 private_key.pem
  26. -rw-r--r-- 1 mysql mysql 452 Jan 31 03:07 public_key.pem
  27. -rw-r--r-- 1 mysql mysql 1112 Jan 31 03:07 server-cert.pem
  28. -rw------- 1 mysql mysql 1676 Jan 31 03:07 server-key.pem
  29. drwxr-x--- 2 mysql mysql 12288 Jan 31 03:07 sys
  30. drwxr-x--- 2 mysql mysql 4096 Jan 31 03:07 xxl_job

4、然后替换pvc存储:

 5、mysql容器运行时可能有一个报错:

InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but

解决方案:

需要删除两个文件即可:

  1. root@mysql-ozthj-b7b7cb9cd-m8hr4:/var/lib/mysql# rm -rfv ib_logfile0
  2. root@mysql-ozthj-b7b7cb9cd-m8hr4:/var/lib/mysql# rm -rfv ib_logfile1

然后重新启动一下mysql容器即可:

  1. [mysql] [2024-01-31 11:14:42] 2024-01-31T03:14:42.386544Z 0 [Note] Plugin 'FEDERATED' is disabled.
  2. [mysql] [2024-01-31 11:14:42] 2024-01-31T03:14:42.396895Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
  3. [mysql] [2024-01-31 11:14:42] 2024-01-31T03:14:42.396920Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
  4. [mysql] [2024-01-31 11:14:42] 2024-01-31T03:14:42.398866Z 0 [Warning] CA certificate ca.pem is self signed.
  5. [mysql] [2024-01-31 11:14:42] 2024-01-31T03:14:42.398926Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
  6. [mysql] [2024-01-31 11:14:42] 2024-01-31T03:14:42.399541Z 0 [Note] InnoDB: Buffer pool(s) load completed at 240131 3:14:42
  7. [mysql] [2024-01-31 11:14:42] 2024-01-31T03:14:42.400190Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
  8. [mysql] [2024-01-31 11:14:42] 2024-01-31T03:14:42.400242Z 0 [Note] IPv6 is available.
  9. [mysql] [2024-01-31 11:14:42] 2024-01-31T03:14:42.400257Z 0 [Note] - '::' resolves to '::';
  10. [mysql] [2024-01-31 11:14:42] 2024-01-31T03:14:42.400277Z 0 [Note] Server socket created on IP: '::'.
  11. [mysql] [2024-01-31 11:14:42] 2024-01-31T03:14:42.402599Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
  12. [mysql] [2024-01-31 11:14:43] 2024-01-31T03:14:43.014325Z 0 [Note] Event Scheduler: Loaded 0 events
  13. [mysql] [2024-01-31 11:14:43] 2024-01-31T03:14:43.014613Z 0 [Note] mysqld: ready for connections.
  14. [mysql] [2024-01-31 11:14:43] Version: '5.7.32' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)

三、验证业务数据:

经过业务人员的验证及功能验证,数据是正确的,没有任何问题。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/思考机器4/article/detail/60115
推荐阅读
相关标签
  

闽ICP备14008679号