赞
踩
包括详细配置、常见报错等
在 .cnf 中 `[mysqld]`下配置:
[mysqld]
# 服务器基础参数
port=3308
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
# GTID:
# 服务器id,设置为机器 IP 地址后三位即可
server_id=188
# 开启gtid模式
gtid_mode=on
# 强制gtid一致性,开启后对于特定create table不被支持
enforce_gtid_consistency=on
# binlog:
# 二进制日志文件存放路径
log_bin = mysql-bin
log-slave-updates=true
# 强烈建议,其他格式可能造成数据不一致
binlog_format=row
# relay log:
skip_slave_start=1
切记,配置完成后,重启数据库服务,连接数据库并验证配置是否生效(不报错,基本都是生效了)。
在 .cnf 中 `[mysqld]`下配置:
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure_file_priv=# GTID:
# 开启gtid模式
gtid_mode=on
enforce_gtid_consistency=on# 服务器id,设置为机器 IP 地址后三位
server_id=189# binlog
log-bin=slave-binlog
log-slave-updates=true# 强烈建议,其他格式可能造成数据不一致
binlog_format=row#relay log
skip_slave_start=1
配置完成后,重启数据库服务,连接数据库用同样的方式验证配置。
salve连接到master
MySQL [(none)]>
MySQL [(none)]> change master to master_host='192.168.78.188', master_user='gtid_copy', master_password='123456', master_port=3308, master_auto_position=1;
Query OK, 0 rows affected, 8 warnings (0.02 sec)
MySQL [(none)]> start slave;
Query OK, 0 rows affected, 1 warning (0.00 sec)
MySQL [(none)]>
**特别注意**:只用在从节点 `start slave` 即可,含义为启动从起点的 I/O 线程和SQL线程。
MySQL [(none)]> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for source to send event
Master_Host: 192.168.78.188
Master_User: gtid_copy
Master_Port: 3308
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 2106
Relay_Log_File: 67bf0b455536-relay-bin.000002
Relay_Log_Pos: 2322
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
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: 2106
Relay_Log_Space: 2539
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: 0
Master_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: 188
Master_UUID: 1d9b633d-e1ae-11ec-8ece-0242ac110002
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Replica 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: 1d9b633d-e1ae-11ec-8ece-0242ac110002:1-8
Executed_Gtid_Set: 1d9b633d-e1ae-11ec-8ece-0242ac110002:1-8
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.01 sec)
ERROR: No query specified
MySQL [(none)]>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。