准备环境
属性 主数据库 从数据库节点 Mysql-Master01 Mysql-Slave01
系统 CentOS Linux release 7.5.1804 (Minimal) CentOS Linux release 7.5.1804 (Minimal)
内核 3.10.0-862.el7.x86_64 3.10.0-862.el7.x86_64
SELinux setenforce 0 | disabled setenforce 0 | disabled
Firewlld systemctl stop/disable firewalld systemctl stop/disable firewalld
IP地址 172.16.70.37 172.16.70.181
Master01,Slave01相同操作部分,以Master01为例。
# 时间同步 [root@Mysql-Master01 ~]# yum install -y ntp [root@Mysql-Master01 ~]# systemctl start ntpd && systemctl enable ntpd [root@Mysql-Master01 ~]# timedatectl set-timezone Asia/Shanghai # yum安装MySQL5.7(默认最新版本) [root@Mysql-Master01 ~]# wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm [root@Mysql-Master01 ~]# yum localinstall -y mysql57-community-release-el7-10.noarch.rpm [root@Mysql-Master01 ~]# yum repolist enabled | grep "mysql.*-community.*" [root@Mysql-Master01 ~]# yum install -y mysql-community-server [root@Mysql-Master01 ~]# mysql -V mysql Ver 14.14 Distrib 5.7.35, for Linux (x86_64) using EditLine wrapper # 启动MySQL [root@Mysql-Master01 ~]# systemctl start mysqld && systemctl enable Too few arguments. [root@Mysql-Master01 ~]# systemctl start mysqld && systemctl enable mysqld [root@Mysql-Master01 ~]# netstat -nutpl | grep mysql tcp6 0 0 :::3306 :::* LISTEN 2256/mysqld [root@Mysql-Master01 ~]# ps -ef | grep mysql mysql 2256 1 0 12:09 ? 00:00:08 /usr/sbin/mysqld --daemonize --pid-file=http://www.likecs.com/var/run/mysqld/mysqld.pid # MySQL安全初始化 [root@Mysql-Master01 ~]# grep 'temporary password' /var/log/mysqld.log 2021-08-19T04:08:59.720748Z 1 [Note] A temporary password is generated for root@localhost: .!aTlyih4r2y [root@Mysql-Master01 ~]# mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: # 输入MySQL初始密码 .!aTlyih4r2y The existing password for the user account root has expired. Please set a new password. New password: # 输入符合复杂密码策略的新密码 Re-enter new password: # 再次输入 The 'validate_password' plugin is installed on the server. The subsequent steps will run with the existing configuration of the plugin. Using existing password for root. Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : n # 上面以已经修改了,无需再修改 ... skipping. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y # 是否删除匿名用户 Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y # 是否禁用root远程登录 Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y # 是否删除test库和对test库的访问权限 - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y # 是否刷新授权表使修改生效 Success. All done!