摘要:腾讯云云数据库到期了,续费价格太贵了......orz记录一次mysql5.7迁移过程

环境准备

安装系统

# 一键重装系统为debian 12
# 重装后用户名为root 密码默认为LeitboGi0ro
wget --no-check-certificate -qO InstallNET.sh 'https://raw.githubusercontent.com/leitbogioro/Tools/master/Linux_reinstall/InstallNET.sh' && chmod a+x InstallNET.sh
bash InstallNET.sh -debian

debian系统版本为debian 12,具体版本如下:

root@host:~# uname -a
Linux host 6.1.0-25-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.106-3 (2024-08-26) x86_64 GNU/Linux

root@host:~# cat /etc/*release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

调整虚拟内存

# 使用 dd 命令生成一个文件块,大小为自己想设置的swap分区大小
dd if=/dev/zero of=/tmp/swapfile bs=1M count=1024
cd /tmp
# 将生成的文件格式化为swap格式文件
mkswap swapfile
# 为了安全将交换分区文件权限设为0600
chmod 0600 swapfile
# 启用虚拟内存
swapon swapfile
# 查看虚拟内存是否启用成功
swapon -s

# 在/etc/fstab文件添加 /tmp/swapfile swap swap defaults 0 0
# 保证开机自动挂载虚拟内存
nano /etc/fstab

# 修改swap分区优先级,当内存占用超过90%的时候使用虚拟内存
echo "vm.swappiness=10" >> /etc/sysctl.conf
# 使修改swap分区优先级的生效
sysctl -p

修改单个进程能打开的最大文件数

# 查看内核中单个进程可打开的最大文件句柄的数量
root@host:~# cat /proc/sys/fs/nr_open
1048576


# 根据上面得到的结果,修改所有用户单个进程可打开的文件句柄的数量限制
sudo tee -a /etc/security/limits.conf << EOF
*               hard    nofile          1048576
*               soft    nofile          1048576
root            hard    nofile          1048576
root            soft    nofile          1048576
EOF

修改时区为上海

timedatectl set-timezone 'Asia/Shanghai'

安装mysql 5.7

debian 12原生没有提供使用apt安装mysql 5.7的方法,因为mysql 5.7实在太老了。
这里采用下载debian 10下的安装包安装的方法。

运行如下命令即可

wget https://cdn.mysql.com/archives/mysql-5.7/mysql-server_5.7.41-1debian10_amd64.deb-bundle.tar
tar -xvf mysql-server_5.7.41-1debian10_amd64.deb-bundle.tar
apt install -y ./mysql-common_5.7.41-1debian10_amd64.deb ./libmysqlclient20_5.7.41-1debian10_amd64.deb ./mysql-community-client_5.7.41-1debian10_amd64.deb ./mysql-client_5.7.41-1debian10_amd64.deb ./mysql-community-server_5.7.41-1debian10_amd64.deb ./mysql-server_5.7.41-1debian10_amd64.deb

mysql 5.7安装包备份地址:https://cloud.189.cn/web/share?code=Q3qAJji2EfAj(访问码:whm8)

安装python3环境

apt-get update
apt install python3
apt install python3-pip
pip3 install pymysql --break-system-packages
pip3 install retry --break-system-packages
pip3 install loguru --break-system-packages
pip3 install requests --break-system-packages
pip3 install yagmail --break-system-packages
pip3 install pycryptodome --break-system-packages
文章目录