当前位置:Gxlcms > 数据库问题 > MySQL主从复制

MySQL主从复制

时间:2021-07-01 10:21:17 帮助过:19人阅读

版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。 C:\Users\Administrator>mysql -u root -p Enter password: **** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 5.7.20-log MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. mysql> grant replication slave on *.* to ‘slave‘@‘%‘ identified by ‘slave‘; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> show master status; +------------------+----------+--------------+------------------+--------------- ----+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_ Set | +------------------+----------+--------------+------------------+--------------- ----+ | mysql-bin.000002 | 1483 | | | | +------------------+----------+--------------+------------------+--------------- ----+ 1 row in set (0.00 sec) mysql>

 其中“grant replication slave on *.* to ‘slave‘@‘%‘ identified by ‘slave‘;” ,在主库上为slave账号分配了replication 权限

“show master status;” 查看主服务器BIN日志的信息(执行完之后记录下这两值,然后在配置完从服务器之前不要对主服务器进行任何操作,因为每次操作数据库时这两值会发生改变).

5、配置从库

mysql> stop slave;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    3
Current database: mysql

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show slave status;
Empty set (0.00 sec)
:: 此处配置的是主库的地址
mysql> change master to master_host=‘**.**.**.**‘;
Query OK, 0 rows affected (0.07 sec)

mysql> change master to master_user=‘slave‘;
Query OK, 0 rows affected, 2 warnings (0.04 sec)

mysql> change master to master_password=‘slave‘;
Query OK, 0 rows affected, 2 warnings (0.04 sec)
:: 与上一步在主库上查询的结果一致即可
mysql> change master to master_log_file=‘mysql-bin.000002‘;
Query OK, 0 rows affected, 1 warning (0.04 sec)
:: 与上一步在主库上查询的结果一致即可
mysql> change master to master_log_pos=1483;
Query OK, 0 rows affected (0.04 sec)
:: 开始主从复制
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)

6、配置完成

如果上述步骤都正常执行完毕,那么现在就配置完成了

使用Navicat等可视化连接工具对主库做建表、插入、删除、修改等操作

从库会随之更新

 

MySQL主从复制

标签:执行   min   就是   增删改   使用   sla   current   mysq   set   

人气教程排行