网站建设资讯

NEWS

网站建设资讯

怎么使用MySQLmaster/slave-创新互联

本篇内容介绍了“怎么使用MySQL master/slave”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

专注于为中小企业提供成都网站设计、成都做网站、外贸网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业新丰免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了1000多家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

Master my.ini

  1. basedir = D:\mysql_test\mysql-5.7.17-master

  2. datadir = D:\mysql_test\mysql-5.7.17-master\data

  3. port = 3306

  4. log-bin=mysql-bin

  5. server_id=1

  6. binlog-ignore-db=information_schema

  7. binlog-ignore-db=cluster

  8. binlog-ignore-db=mysql

  9. binlog-do-db=test

Slave my.ini

  1. basedir = D:\mysql_test\mysql-5.7.17-slave

  2. datadir = D:\mysql_test\mysql-5.7.17-slave\data

  3. port = 3307

  4. log-bin=mysql-bin

  5. server-id=2

  6. binlog-ignore-db=information_schema

  7. binlog-ignore-db=cluster

  8. binlog-ignore-db=mysql

  9. replicate-do-db=test

  10. replicate-ignore-db=mysql

  11. log-slave-updates

  12. slave-skip-errors=all

  13. slave-net-timeout=60

Master 运行
mysql> CREATE USER 'rep'@'%' IDENTIFIED BY 'rep';
mysql> GRANT FILE ON *.* TO 'rep'@'%' IDENTIFIED BY 'rep';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'rep'@'%' IDENTIFIED BY 'rep';
mysql> FLUSH PRIVILEGES;

mysql> show master status;
+------------------+----------+--------------+----------------------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB                 | Executed_Gtid_Set |
+------------------+----------+--------------+----------------------------------+-------------------+
| mysql-bin.000002 |     4570 | test         | information_schema,cluster,mysql |                   |
+------------------+----------+--------------+----------------------------------+-------------------+

Slave 运行
mysql> CREATE USER 'rep'@'%' IDENTIFIED BY 'rep';
mysql> change master to master_host='localhost',master_user='rep',master_password='rep',master_log_file='mysql-bin.000002', master_log_pos=4570;

mysql> start slave;
mysql> show slave status;

Slave_IO_Running 和 Slave_SQL_Running都是 Yes 表示成功。
Master创建数据库,创建表,添加数据,会自动复制到Slave。 

“怎么使用MySQL master/slave”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联-成都网站建设公司网站,小编将为大家输出更多高质量的实用文章!


分享名称:怎么使用MySQLmaster/slave-创新互联
文章地址:http://cdweb.net/article/dipegg.html