步骤
一、安装mysql(主从)
1、安装
cd /usr/local/src/
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum -y install mysql-server
service mysqld restart
2、设置密码
修改配置文件
vim /etc/my.cnf
增加一行代码
[mysqld]
skip-grant-tables
进入mysql
mysql -u root -p
3、更改密码策略
mysql -> set global validate_password_policy=LOW;
mysql -> set global validate_password_length=4;
4、重制密码
mysql -> alter user 'root'@'localhost' identified by‘root';
5、刷新权限
mysql -> flush privileges
二、主从配置(主:192.168.1.25,从:192.168.1.28)
1、在主服务器上修改配置文件
vim /etc/my.cnf
添加:
log-bin=mysql-bin
server-id=1
log-slave-updates
2、退出后重启服务
systemctl restart mysqld.service
3、在从服务器上配置文件
vim /etc/my.cnf
添加:
relay-log=relay-bin
server-id=2
退出后重启服务:
systemctl restart mysqld.service
4、查看从服务器的中继日志是否启动成功
mysql > show global variables like '%relay%';
5、在主服务器上创建有复制权限的账号
grant replication slave on *.* to 'root'@'192.168.1.%' identified by 'root';
刷新权限:
flush privileges;
6、在主服务器上查看状态信息
mysql > show master status;
7、从服务器上
stop slave;
8、从服务器上连接主服务器
change master to master_host='主服务器的ip',master_user='root',master_password=root,master_log_file='mysql-bin.000001',master_log_pos=609;
9、从服务器启动复制线程:
start slave
show slave status \G;
lave_IO_Running和Slave_SQL_Running两个线程必须都为Yes。
systemctl stop firewalld.service
10、开启远程连接(主从均要)
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
11、测试