试验环境
系统window
mysql:
使用的是phpstudy自带数据库
主库 定义为 123.207.43.xx
# power by php中文网 2017 www.php.cn 官网下载最新版
[client]
port=3306
[mysql]
default-character-set=utf8
[mysqld]
port=3306
log-error = C:/phpStudy/PHPTutorial/MySQL/mylog/error.log
basedir="C:/phpStudy/PHPTutorial/MySQL/"
datadir="C:/phpStudy/PHPTutorial/MySQL/data/"
character-set-server=utf8
default-storage-engine=MyISAM
#支持 INNODB 引擎模式。修改为 default-storage-engine=INNODB 即可。
#如果 INNODB 模式如果不能启动,删除data目录下ib开头的日志文件重新启动
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
max_connections=512
query_cache_size=0
table_cache=256
tmp_table_size=18M
thread_cache_size=8
myisam_max_sort_file_size=64G
myisam_sort_buffer_size=35M
key_buffer_size=25M
read_buffer_size=64K
read_rnd_buffer_size=256K
sort_buffer_size=256K
innodb_additional_mem_pool_size=2M
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=1M
innodb_buffer_pool_size=47M
innodb_log_file_size=24M
innodb_thread_concurrency=8
innodb_thread_concurrency=8
innodb_thread_concurrency=8
#主从复制
server-id=1
log_bin
sync_binlog=1
binlog_format=MIXED
这里日志采用混合模式
然后主库配置就到这里
接下来我们需要开设来宾访问权限
GRANT ALL PRIVILEGES ON . TO 'myuser'@'%'IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
myuser mypassword随便起 但是要记住这个是你从库登录凭证
我们还需要查询一下log的位置与名字
showmaster status;
记录一下 之后会用到
从库
my.ini配置
主从复制
server-id = 2
只需加入这句话
然后设置连接
mysql>grantreplication slave on . to ‘testcreate’@’192.168.1.61’ identified by ‘123456’;
说明:’testcreate’:同步的数据库;
‘192.168.1.61’:同步的数据库地址;
‘123456’ :同步的数据库密码,在从库配置时需要设置。
mysql>showslave status\G;
执行上述命令显示:
两个yes那么成功
image.png
如果遇到关于position相关的错误,就需要再手动设置以下File/Postion的信息
mysql>Changemaster to master_host = ‘192.168.1.60’
master_user= ‘test’
master_password=’123456’
master_log_file=’mysql-bin.000001’, 主库的文件信息
master_log_pos=’106’;主库的Position信息
把之前查到的名字 和pos填进去
然后slave start