山楂树之恋v1

导航

MySQL的主从复制

一、防火墙的开启、关闭、禁用命令

(1)设置开机启用防火墙:systemctl enable firewalld.service

 

 

(2)设置开机禁用防火墙:systemctl disable firewalld.service

 

 

(3)启动防火墙:systemctl start firewalld

 

 

(4)关闭防火墙:systemctl stop firewalld

 

 

 

(5)检查防火墙状态:systemctl status firewalld

 

  

永久关闭selinux下的强制检查:
要把vim /etc/selinux/config
中的 SELINUX=enforcing
变为 SELINUX=disabled
然后重启虚拟机 如果不重启还需要在输入一条命令:setenforce 0

 

 

 

 

 


主服务器配置:vim /etc/my.cnf
添加:log-bin=mysql-bin
server-id=100

 

 

 

 

 

从服务器配置:vim /etc/my.cnf
添加:relay-log=relay-log-bin
server_id=101
read-only=on

 

 

 

 

 

 

 



主从复制的配置:
vim /var/lib/mysql/auto.cnf //注意:内容要不一样

配置完都要重启mysql: systemctl restart mysqld

 

 

 

 

主: mysql> set global validate_password_policy=low;

 

      mysql> set global validate_password_length=4;

 

 

 

       mysql> grant replication slave on *.* to 'yonghuming'@'%' identified by 'yonghumima';

 

 

 

       mysql> select user,host from mysql.user;

 

 

 

       mysql> show master status\G;

 

 

 


从: 

mysql>  change master to

      -> master_host='%',

      -> master_user='yonghuming',

      -> master_port=3306,

      -> master_log_file='mysql-bin.000005',

      ->  master_log_pos=443;

 

 

 

 

 

 

mysql> start slave;

 

 

 

mysql> show slave status\G;
查看: Slave_IO_Running: Yes // 是否是:yes
Slave_SQL_Running: Yes

 

 

主: 主服务器的数据库要完全备份:
mysqldump --user=root -p --lock-all-tables --all-databases > all.sql

 

 

把主服务器的备份传到从服务器:
scp ./all.sql root@172.16.188.242:/root/

 

 

从: 从数据库中把传过来的备份恢复:
source /root/all.sql

 

 



注意: ---------试试从数据库有没有同步---------


立即启动一个服务:
systemctl start apache.service
立即停止一个服务:
systemctl stop apache.service
重启一个服务
systemctl restart apache.service

 

 

 

show variables like '%format';
show variables like '%image';


主从复制的启动跟关闭:
启动:start slave;

停止:stop slave;

 

posted on 2020-02-19 15:00  山楂树之恋v1  阅读(121)  评论(0编辑  收藏  举报