博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql主从配置
阅读量:7238 次
发布时间:2019-06-29

本文共 5133 字,大约阅读时间需要 17 分钟。

hot3.png

http://blog.csdn.net/zyw_java/article/details/72984112

文中有一处错误XSX自己发现的 master_port=3316 没指定

 

010135_PYjh_3018126.png

 

2、数据库安装

可以参考之前写的文章:

这里贴一下Slave数据库安装的日志

Microsoft Windows [版本 6.1.7601]版权所有 (c) 2009 Microsoft Corporation。保留所有权利。C:\Windows\system32>cd C:\Program Files\mysql-5.7.18-win32-slave\binC:\Program Files\mysql-5.7.18-win32-slave\bin>mysqld  --initializeC:\Program Files\mysql-5.7.18-win32-slave\bin>cd  ../dataC:\Program Files\mysql-5.7.18-win32-slave\data>TYPE Javen-PC.err2017-06-29T02:41:51.068120Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2017-06-29T02:41:51.573560Z 0 [Warning] InnoDB: New log files created, LSN=457902017-06-29T02:41:51.643760Z 0 [Warning] InnoDB: Creating foreign key constraintsystem tables.2017-06-29T02:41:51.699920Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generatinga new UUID: 818f5c2f-5c74-11e7-8dff-000c29b2597f.2017-06-29T02:41:51.699920Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2017-06-29T02:41:51.713960Z 1 [Note] A temporary password is generated for root@localhost: =rc%=eBVg0AYC:\Program Files\mysql-5.7.18-win32-slave\data>cd ..C:\Program Files\mysql-5.7.18-win32-slave>cd binC:\Program Files\mysql-5.7.18-win32-slave\bin>mysqld -install MySQL2Service successfully installed.C:\Program Files\mysql-5.7.18-win32-slave\bin>net start MySQL2MySQL2 服务正在启动 .MySQL2 服务已经启动成功。C:\Program Files\mysql-5.7.18-win32-slave\bin>mysql -u root -p=rc%=eBVg0AY -P3308Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.7.18Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';Query OK, 0 rows affected (0.00 sec)mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> FLUSH  PRIVILEGES;Query OK, 0 rows affected (0.00 sec)mysql> exitBye

010357_1YaV_3018126.png

010439_wy3x_3018126.png

010501_EcOY_3018126.png

010517_Nz37_3018126.png

4.2 重启从数据库并设置Slave数据库

net stop MySQL2net start MySQL2

登录从数据库并做如下设置

mysql> stop slave;  #关闭Slavemysql> change master to master_host='192.168.1.103',master_user='javen',master_password='123456',master_log_file='mysql-bin.000001', master_log_pos= 2519;mysql> start slave;  #开启Slave

注意:在这里指定Master的信息,master_log_file是在配置Master的时候的File选项, master_log_pos是在配置Master的Position 选项,这里要进行对应。

4.3 查看Slave配置的信息

show slave status 查看配置的信息:

mysql> show slave status \G;*************************** 1. row ***************************               Slave_IO_State: Waiting for master to send event                  Master_Host: 192.168.1.103                  Master_User: mysync                  Master_Port: 3306                Connect_Retry: 60              Master_Log_File: mysql-bin.000001          Read_Master_Log_Pos: 1192               Relay_Log_File: Javen-PC-relay-bin.000002                Relay_Log_Pos: 320        Relay_Master_Log_File: mysql-bin.000001             Slave_IO_Running: Yes            Slave_SQL_Running: Yes              Replicate_Do_DB:          Replicate_Ignore_DB: mysql           Replicate_Do_Table:       Replicate_Ignore_Table:      Replicate_Wild_Do_Table:  Replicate_Wild_Ignore_Table:                   Last_Errno: 0                   Last_Error:                 Skip_Counter: 0          Exec_Master_Log_Pos: 1192              Relay_Log_Space: 530              Until_Condition: None               Until_Log_File:                Until_Log_Pos: 0           Master_SSL_Allowed: No           Master_SSL_CA_File:           Master_SSL_CA_Path:              Master_SSL_Cert:            Master_SSL_Cipher:               Master_SSL_Key:        Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: No                Last_IO_Errno: 0                Last_IO_Error:               Last_SQL_Errno: 0               Last_SQL_Error:  Replicate_Ignore_Server_Ids:             Master_Server_Id: 1                  Master_UUID: 818f5c2f-5c74-11e7-8dff-000c29b2597f             Master_Info_File: C:\Program Files\mysql-5.7.18-win32-slave\data\master.info                    SQL_Delay: 0          SQL_Remaining_Delay: NULL      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates           Master_Retry_Count: 86400                  Master_Bind:      Last_IO_Error_Timestamp:     Last_SQL_Error_Timestamp:               Master_SSL_Crl:           Master_SSL_Crlpath:           Retrieved_Gtid_Set:            Executed_Gtid_Set:                Auto_Position: 0         Replicate_Rewrite_DB:                 Channel_Name:           Master_TLS_Version:1 row in set (0.00 sec)ERROR:No query specifiedmysql>

 

5、关闭掉主数据库的读取锁定

mysql> unlock tables;
  • 1

6、在主数据库中创建一个表以及添加数据测试

在主数据库(Master)添加一个test数据库并在其中添加t1的数据表。如下图

Master数据库

在从数据库(Slave)自动同步,如下图

Slave数据库

如有问题欢迎留言….

转载于:https://my.oschina.net/u/3018126/blog/1584842

你可能感兴趣的文章
机器学习之特征选择---特征选择算法
查看>>
可视化工具之 IGV 使用方法
查看>>
redis修改端口号
查看>>
java中四种阶乘的计算
查看>>
mybatis 查询语句(按条件查询)
查看>>
Android代码内存优化建议-Android官方篇
查看>>
PHP Date()函数详细参数
查看>>
在vs2010中编译log4cxx-0.10.0具体方法(从下载、编译、解决错误具体介绍)
查看>>
怎样挂载 云磁盘
查看>>
SQL Server 2014 虚拟机的自动备份 (Resource Manager)
查看>>
Multipart to single part feature
查看>>
Delphi XE2 之 FireMonkey 入门(22) - 数据绑定: BindingSource、BindingName、FindBinding()、Binding[]...
查看>>
Linux 脚本编写基础
查看>>
ASP.NET 2.0 中的资源与本地化
查看>>
【转载】MongoDb环境部署
查看>>
Entity Framework快速入门笔记第2篇—增删改查
查看>>
【转载】Programming WCF Services翻译笔记(七)
查看>>
xml中实体引用
查看>>
TryCatchFinallyProcessHelper
查看>>
超强文本编辑器SciTE配置方法详细实例
查看>>