MySQL怎么全体物理迁移

需求
两台服务器安装了相同版本的MySQL需要把其中一台数据完全迁移至另外一台服务器

  1. 环境查看
    系统环境
# cat /etc/redhat-release 
Rocky Linux release 9.3 (Blue Onyx)
[root@Rocky9MySQLTest003104 ~]# uname -a
Linux Rocky9MySQLTest003104 5.14.0-362.8.1.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 8 17:36:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

软件环境

# mysql --version
mysql  Ver 8.0.36 for Linux on x86_64 (MySQL Community Server - GPL)
  1. 迁移
    安装步骤不详述
    源服务器和目标服务器分别停止MySQL
systemctl stop mysqld

目标服务器把文件夹/var/lib/mysql备份
从源服务器把文件夹完整复制过来

scp -r mysql root@192.168.3.104:/var/lib/

把目录权限设置为用户mysql

chown -R mysql:mysql /var/lib/mysql

关闭senlinux

setenforce 0
# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
# See also:
# https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/using_selinux/changing-selinux-states-and-modes_using-selinux#changing-selinux-modes-at-boot-time_changing-selinux-states-and-modes
#
# NOTE: Up to RHEL 8 release included, SELINUX=disabled would also
# fully disable SELinux during boot. If you need a system with SELinux
# fully disabled instead of SELinux running with no policy loaded, you
# need to pass selinux=0 to the kernel command line. You can use grubby
# to persistently set the bootloader to boot with selinux=0:
#
#    grubby --update-kernel ALL --args selinux=0
#
# To revert back to SELinux enabled:
#
#    grubby --update-kernel ALL --remove-args selinux
#
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

能正常启动即可,原来的数据以及用户均迁移过来

systemctl start mysqld
posted @ 2026-08-31 14:40  minseo  阅读(6)  评论(0)    收藏  举报