一、环境说明
MASTER: [root@server01 ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) 外网IP:192.168.100.20 内网IP:192.168.200.20 SLAVE: [root@server02 ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) 外网IP:192.168.100.21 内网IP:192.168.200.21
二、两台机器分别安装MySQL8.033版本
注意:主从机器MySQL版本要保持一致
从官网下载MySQL源 [root@server01 ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm 安装MySQL [root@server01 ~]# yum install -y mysql80-community-release-el7-7.noarch.rpm [root@server01 ~]# yum -y install mysql-community-server [root@server01 ~]# mysql -V mysql Ver 8.0.33 for Linux on x86_64 (MySQL Community Server - GPL) 启动mysql并设为开机自启 [root@server01 ~]# systemctl start mysqld.service [root@server01 ~]# systemctl enable mysqld.service 查看mysql默认登录密码 [root@server01 ~]# cat /var/log/mysqld.log|grep 'A temporary password' 2023-06-28T21:12:45.766727Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: uQof%up,J5hH 登录mysql [root@server01 ~]# mysql -uroot -puQof%up,J5hH mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.33 Copyright (c) 2000, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> \q Bye
两台机器执行同样操作进行安装
三、防火墙开放3306端口
[root@server01 ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent success [root@server01 ~]# systemctl restart firewalld
四、mysql主从配置