mysql 同一服务器同步_MySQL 同一台服务器同步数据

声明:我配置出来的slave_io_running和slave_sql_running都是yes。但是数据并没有同步!

希望有遇到相同问题的朋友,能够告诉我一下解决方案?

首先,如何在同一个服务器安装两个MySQL

接着我们配置两个mysql同步数据

一  先看mysql1的my.ini

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the

# *** default location during install, and will be replaced if you

# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

# These are commonly set, remove the # and set as required.

# basedir = .....

# datadir = .....

# port = .....

# server_id = .....

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

# 以下内容手动添加

[client]

port=3307

default-character-set=utf8

[mysqld]

#skip-grant-tables

#从库配置

server_id=1

#需要同步的表,不写则默认整个库同步

binlog-do-db=testdb

slave_parallel_type='logical_clock'

slave_parallel_workers=4

log_bin=mysql-bin

log_bin-index=mysql-bin.index

#端口

port=3306

character_set_server=utf8

#我的data和bin目录分成了连个,所以路径有些不一样,大家按照自己的来就行

#解压目录

basedir=C:\ProgramData\MySQL\MySQL Server 5.7

#解压目录下data目录

datadir=C:\ProgramData\MySQL\MySQL Server 5.7\data

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[WinMySQLAdmin]

C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe

二  在看mysql2的my.ini

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the

# *** default location during install, and will be replaced if you

# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

# These are commonly set, remove the # and set as required.

# basedir = .....

# datadir = .....

# port = .....

# server_id = .....

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

# 以下内容手动添加

[client]

port=3307

default-character-set=utf8

[mysqld]

#从库配置

server_id=2

#这个是你需要覆盖的库

replicate-do-db=kps_common

relay-log-index=slave-relay-bin.index

relay-log=slave-relay-bin

#端口

port=3307

character_set_server=utf8

#我的data和bin目录分成了连个,所以路径有些不一样,大家按照自己的来就行

#解压目录

basedir=C:\ProgramData\MySQL1\MySQL Server 5.7

#解压目录下data目录

datadir=C:\ProgramData\MySQL1\MySQL Server 5.7\data

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[WinMySQLAdmin]

C:\Program Files\MySQL1\MySQL Server 5.7\bin\mysqld.exe

三  命令配置mysql1

接着,先配置mysql1

打开cmd,然后转到mysql1的bin目录

1 cd\

2 cd C:\Program Files\MySQL\MySQL Server 5.7\bin

3 输入 mysql -uroot -p

4 输入密码 登录成功

5 show master status;

第5步,完成后,出现下图:(图片是拷贝的,主要记住File和Position)

16b118f1ae1b4683686e013fd0e9fca3.png

最后使用语句

PS:这里必须要填192.168.1.88的ip,而不是127.0.0.1。不然之后会Slave_IO_Running:Connecting

这个问题困扰了我2天,后来偶然的使用ip来赋值用户权限,才正确!

create user slave;

grant replication slave on *.* to 'slave'@'192.168.1.88'identified by '123';

flush privileges;

四  命令配置mysql2

同上面一样,先打开cmd,然后转到mysql2的bin目录

然后登陆。

接着运行

CHANGE MASTER TO

master_host = '192.168.1.88',

master_user = 'slave',

master_password = '123',

master_log_file = 'bin_log.000002',

master_log_pos = 631;

然后运行

start slave;

show slave status \G;

出现这个就正确了

c00e976e0ef007c03d9cd27d5a7c6bdf.png

参考:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值