MySQL 同一台服务器同步数据

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

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

 

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

https://blog.csdn.net/hanjun0612/article/details/81236694

 

接着我们配置两个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

最后使用语句

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;

出现这个就正确了

 

 

参考:

https://blog.csdn.net/tribalelders/article/details/53894194

https://www.cnblogs.com/naruto123/p/8138708.html

 

posted @ 2018-08-09 15:55  正怒月神  阅读(162)  评论(0编辑  收藏  举报