mysql-5.7.22 主从同步(读写分离) 重启失效

本文详细介绍了如何重启主从数据库同步配置的过程,包括备份数据库、同步表结构、配置主从连接等步骤,并针对可能出现的问题提供了排查建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

重启主从库同步配置

0、 备份数据库(很重要!主从库都要备份) 
1、同步数据库表结构,让主从库表结构保持一致 
2、在主库环境下,运行SHOW MASTER STATUS,输出如下: 
这里写图片描述

3、记住file名和position名,切换至从库环境 
4、在从库环境下运行stop slave 
5、在从库环境下运行

   CHANGE  MASTER TO 
   MASTER_HOST='188.180.81.176',MASTER_PORT=3307,MASTER_USER='username',  
   MASTER_PASSWORD='111111',             
   MASTER_LOG_FILE='mysql-bin.000001',  MASTER_LOG_POS=98;

 (Host为主库ip地址,MASTER_USER和MASTER_PASSWORD分别为配置主从同步时创建的帐号和密码,file和Pos分别为主库file名、position名)

如出现错误,重置slave :reset slave;

6、运行start slave; 
7、运行show slave status\G ;检查输出是否包含如下:

...
  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes
...
  •  

8、在主库上添加一条数据,查看从库是否完成同步。

若要求从库同步主库,步骤与上述一直,主从环境的相关参数记得切换即可。

可能会遇到的麻烦

1、Slave_IO_Running: Connecting : 
导致lave_IO_Running 为connecting 的原因主要有以下 3 个方面:

1、网络不通 
2、密码不对 
3、pos不对

检查一下主从环境防火墙是否拦截了请求,然后查看 MASTER_LOG_POS 的值是否为目标地址的position地址,重新输入后如果仍然为connection,则需要检查下主从同步配置时配置的账户密码是否正确(项目一般配置后都会留文档,记得查询一下)。

2、Slave_SQL_Running: No : 
按上述步骤重启主从库配置即可解决。

转载于:https://my.oschina.net/glenxu/blog/1808704

[root@lumingdong tool]# rpm -ivh mysql-community-common-*.rpm warning: mysql-community-common-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] package mysql-community-common-5.7.22-1.el7.x86_64 is already installed [root@lumingdong tool]# rpm -ivh mysql-community-libs-*.rpm warning: mysql-community-libs-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] package mysql-community-libs-5.7.22-1.el7.x86_64 is already installed [root@lumingdong tool]# rpm -ivh mysql-community-client-*.rpm warning: mysql-community-client-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] package mysql-community-client-5.7.22-1.el7.x86_64 is already installed [root@lumingdong tool]# rpm -ivh mysql-community-server-*.rpm warning: mysql-community-server-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ################################# [100%] file /usr/bin/mysql from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-client-5.7.22-1.el7.x86_64 file /usr/bin/mysqladmin from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-client-5.7.22-1.el7.x86_64 file /usr/bin/mysqldump from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-client-5.7.22-1.el7.x86_64 file /usr/bin/mysqlpump from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-client-5.7.22-1.el7.x86_64 file /etc/my.cnf from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/bin/my_print_defaults from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /var/lib/mysql from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/bin/mysql_install_db from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/bin/mysql_ssl_rsa_setup from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/bin/mysql_tzinfo_to_sql from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/bin/mysql_upgrade from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/adt_null.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/auth_socket.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/authentication_ldap_sasl_client.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/connection_control.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/group_replication.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/innodb_engine.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/keyring_file.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/keyring_udf.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/libmemcached.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/locking_service.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/mypluglib.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/mysql_no_login.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/mysqlx.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/rewrite_example.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/rewriter.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/semisync_master.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/semisync_slave.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/validate_password.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/version_token.so from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 file /usr/sbin/mysqld from install of mysql-community-server-minimal-5.7.22-1.el7.x86_64 conflicts with file from package mysql-community-server-5.7.22-1.el7.x86_64 package mysql-community-server-5.7.22-1.el7.x86_64 is already installed file /etc/my.cnf conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/bin/my_print_defaults conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/bin/mysql_install_db conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/bin/mysql_ssl_rsa_setup conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/bin/mysql_tzinfo_to_sql conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/bin/mysql_upgrade conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/adt_null.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/auth_socket.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/authentication_ldap_sasl_client.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/connection_control.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/group_replication.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/innodb_engine.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/keyring_file.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/keyring_udf.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/libmemcached.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/locking_service.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/mypluglib.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/mysql_no_login.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/mysqlx.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/rewrite_example.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/rewriter.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/semisync_master.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/semisync_slave.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/validate_password.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/lib64/mysql/plugin/version_token.so conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /usr/sbin/mysqld conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 file /var/lib/mysql conflicts between attempted installs of mysql-community-server-5.7.22-1.el7.x86_64 and mysql-community-server-minimal-5.7.22-1.el7.x86_64 [root@lumingdong tool]# chown -R mysql:mysql /var/log/mysqld.logchown -R mysql:mysql /var/log/mysqld.log chown: cannot access ‘/var/log/mysqld.logchown’: No such file or directory chown: cannot access ‘mysql:mysql’: No such file or directory [root@lumingdong tool]# chmod 755 /var/log/mysqld.log [root@lumingdong tool]# systemctl start mysqld Failed to get D-Bus connection: No such file or directory [root@lumingdong tool]#
最新发布
08-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值