From 534ab490f7f09eb088e43452c946ac8fca16dd1d Mon Sep 17 00:00:00 2001 From: root Date: Mon, 27 Jun 2022 10:58:53 +0800 Subject: [PATCH] *: MySQL 5.7 upgrade to MySQL8.0 #426 --- docs/zh-cn/upgrade80sh.md | 36 ++++++++ upgrade80.sh | 168 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 docs/zh-cn/upgrade80sh.md create mode 100644 upgrade80.sh diff --git a/docs/zh-cn/upgrade80sh.md b/docs/zh-cn/upgrade80sh.md new file mode 100644 index 00000000..5730e674 --- /dev/null +++ b/docs/zh-cn/upgrade80sh.md @@ -0,0 +1,36 @@ +Contents +================= + + * [简介](#简介) + * [限制](#限制) + * [用法](#用法) + * [Check](#check) + * [Upgrade](#upgrade) + +# 简介 +从 MySQL5.7 升级到 MySQL8.0 有两种方式, 一种是直接从 MySQL5.7 的数据文件中升级, 这种方式被称为 In-place Upgrade, 另一种是通过`msqldump` 进行逻辑备份与恢复, 这种方式被称为 `logic upgrade` , `updrade80.sh` 是采用第一种方式进行的. + +# 限制 +采用`in-place upgrade` 速度较快,但是必须要谨慎, 严格参考 [mysql手册](https://dev.mysql.com/doc/refman/8.0/en/upgrade-binary-package.html#upgrade-procedure-inplace) 要求进行检查, 并且事先要做好备份. + +# 用法 + 建议实现执行 Check, 如果check 没有任何信息, 然后执行 Update 命令, +## Check +用法: +``` +upgrade80.sh check [集群名称] +``` +示例: +``` +./upgrade80.sh check sample +``` + +## Upgrade +用法 +``` +./upgrade80.sh update [集群名称] [mysql80的sidecar镜像] +``` +示例: +``` + ./upgrade80.sh update sample "radondb/mysql80-sidecar:v2.2.0" + ``` \ No newline at end of file diff --git a/upgrade80.sh b/upgrade80.sh new file mode 100644 index 00000000..50e7622b --- /dev/null +++ b/upgrade80.sh @@ -0,0 +1,168 @@ +#!/usr/bin/bash +CLUSTER= +IMAGE= +update () { +# set innodb_fast_shutdown=0 in yaml file +kubectl patch mysql $CLUSTER --type=merge --patch '{"spec": + {"mysqlOpts": + {"mysqlConf": {"innodb_fast_shutdown":"0"} + } + } + }' + +checkReadyOrClosed() { + kubectl get mysqlclusters.mysql.radondb.com -o jsonpath='{.items[0].status.state}' 2>/dev/null |grep -q 'Ready'||kubectl get mysqlclusters.mysql.radondb.com -o jsonpath='{.items[0].status.state}' 2>/dev/null |grep -q 'Closed' +} +checkStatefulSetUpdated() { + # it has ready + # get statefulset ready replicas + ready=$(kubectl get statefulsets.apps -o jsonpath='{.items[0].status.readyReplicas}' 2>/dev/null) + updateVersion=$(kubectl get statefulsets.apps -o jsonpath='{.items[0].status.updateRevision}' 2>/dev/null) + count=$(kubectl get pod -l "app.kubernetes.io/managed-by"="mysql.radondb.com" -l "controller-revision-hash"=$updateVersion |awk 'NR>1{print $1}'|wc -l) + if [ $count -eq $ready ];then + return 0 + else + return 1 + fi +} +waitReady () { + timeout=$1 + SECONDS=0 + echo -n Wating + until checkReadyOrClosed; do + sleep 2 + echo -n "." + if [ $SECONDS -gt $timeout ]; then + echo "timeout" + break + fi + done + echo +} + +waitReady 30 +until checkStatefulSetUpdated; do + echo "waiting for statefulset updated" + echo -n "." + sleep 5 +done +echo +pods=$(kubectl get pod -l "app.kubernetes.io/managed-by"="mysql.radondb.com"|awk 'NR>1{print $1}') +for p in $pods ; do + kubectl exec -it $p -c mysql -- bash <64); +MOF +EOF + # There must be no views with explicitly defined columns names that exceed 64 characters + + # partitioned table + kubectl exec -it svc/$CLUSTER-leader -c mysql -- bash <