一、一般配置主从(这里主是m3300,从是3301、3302)
1.配置m3301
从mysql8里拿出这两个文件到m3301
2.配置my.ini
初始化mysql8
mysqld --initialize-insecure;
安装服务
mysqld -install m3300;
开启服务
net start m3300;
进入mysql
mysql -uroot -P3300;
其他几个服务与上面相同,构建如下:
[En]
Several other services are the same as above, built as follows:
3.在主服务m3300中的操作
建立账号
create user repl identified with mysql_native_password by 'repl';
授权
grant replication slave on *.* to repl;
刷新
flush privileges;
查看主库master
show master status;
4.在从服务中操作m3301
接入主服务设置的账号和日志(根据您自己的主服务)
[En]
Connect the account and log set by the main service (according to your own master service)
change replication source to
source_host='127.0.0.1',
source_user='repl',
source_password='repl',
source_port=3300,
source_log_file='binlog.000003',
source_log_pos=827;
开启主从服务
start slave;和start replica;都可以。
查看是否成功
show slave status \G
如果不成功(请检查配置)
[En]
If unsuccessful (please check the configuration)
没有问题的化还是no请执行
stop slave;
reset slave;
start slave;
show slave status \G
其它的百度吧
5.在主服务中建立数据库从服务中也可查看
6.从库只读配置my.ini
[mysqld]
port=3300
server_id=1
bin_log=binlog
binlog_do_db=db
binlog_ignore_db=information_schema,mysql,performance_schema,sys
read_only=off
super_read_only=off
7.停止主机并清理所有信息
mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> reset slave all;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status;
Empty set (0.00 sec)
mysql> show slave status\G
Empty set (0.00 sec
二、GTID配置主从
1.主库
my.ini配置
[mysqld]
port=3300
gtid_mode=on
enforce_gtid_consistency=on
log_bin=binlog
server-id=80
binlog_format=row
初始化同↑
建立账号
create user abc identified with mysql_native_password by 'abc';
grant repliciation slave on *.* to abc
flush privilrges;
查看主库信息
从库my,ini 配置
port=3301
gtid_mode=on
enforce_gtid_consistency=on
log_bin=binlog
server-id=81
log_slave_updates=1 
初始化同↑
匹配主库
在主库中创建数据库,插入数据,并从库中查看
[En]
Create a database in the main library, insert data, and view from the library
主库m3300
从库m3301
清理同上
三、在docker 中安装mysql并设置主从
ubuntu 安装省略,详细见哔哩哔哩
Original: https://www.cnblogs.com/zcxxcvbn/p/15928285.html
Author: 一份人间烟火
Title: mysql8主从配置
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/507806/
转载文章受原作者版权保护。转载请注明原作者出处!