主库从库的mysql版本必须一样。
1.主库的my.cnf配置文件如下:
[mysqld]
user = mysql
log_timestamps = SYSTEM
basedir = /usr/local/mysql
datadir = /data/mysql_data
pid-file = /data/mysql_data/mysql.pid
socket = /data/mysql_data/mysql.sock
port = 3306
character-set-server= utf8
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
max_connections = 1000
max_connect_errors = 1000
open_files_limit = 65535
wait_timeout= 1800
max_user_connections = 1000
innodb_buffer_pool_size = 2G
innodb_log_buffer_size = 64M
innodb_log_file_size = 500M
table_open_cache = 1024
log-bin = /data/mysql_data/mysql_bin_log/mysql-bin
binlog_format = row
expire_logs_days = 30
server_id = 42 #必须与从库不一致
binlog-ignore-db=information_schema #排除同步数据库
binlog-ignore-db=performance_schema #排除同步数据库
binlog-ignore-db=mysql #排除同步数据库
#binlog-do-db=xunyundb
log_error = /data/mysql_data/mysql-error.log
default-storage-engine = INNODB
[client]
port=3306
socket= /data/mysql_data/mysql.sock2.备库的my.cnf配置文件如下:
[mysqld]
user = mysql
log_timestamps = SYSTEM
basedir = /usr/local/mysql
datadir = /data/mysql_data
pid-file = /data/mysql_data/mysql.pid
socket = /data/mysql_data/mysql.sock
port = 3306
character-set-server= utf8
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
max_connections = 1000
max_connect_errors = 1000
open_files_limit = 65535
wait_timeout= 1800
max_user_connections = 1000
innodb_buffer_pool_size = 10G
innodb_log_buffer_size = 64M
innodb_log_file_size = 1000M
table_open_cache = 1024
log-bin = /data/mysql_data/mysql_bin_log/mysql-bin
binlog_format = row
expire_logs_days = 30
server_id = 50 #必须与主库不一致
relay_log=/data/mysql_data/mysql-relay #指定relay日志地址
relay-log-index=/data/mysql_data/relay-log.index #指定relay日志地址
log_error = /data/mysql_data/mysql-error.log
default-storage-engine = INNODB
[client]
port=3306
socket= /data/mysql_data/mysql.sock3.在主库上建同步的账户,并授权
CREATE USER 'rep'@'192.168.1.150' IDENTIFIED BY 'rep123';
grant replication slave on *.* to 'rep'@'192.168.1.150' ;4. 查看当前主库的binlog
mysql> show master status;
+------------------+----------+--------------+---------------------------------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+---------------------------------------------+-------------------+
| mysql-bin.000006 | 609 | | information_schema,performance_schema,mysql | |
+------------------+----------+--------------+---------------------------------------------+-------------------+
1 row in set (0.00 sec)5. 在从库配置同步信息
CHANGE MASTER TO
MASTER_HOST='192.168.1.146', #主库地址
MASTER_USER='rep', #同步账户
MASTER_PASSWORD='rep123',
MASTER_LOG_FILE='mysql-bin.000006', #查询出来的binlog信息
MASTER_LOG_POS=609,
master_port=3306;6.打开slave,并查看同步状态
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.146
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000006
Read_Master_Log_Pos: 1240
Relay_Log_File: mysql-relay.000006
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000006
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: 1240
Relay_Log_Space: 689
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: 42
Master_UUID: c6368fc6-b99e-11ec-8e01-005056b65858
Master_Info_File: /data/mysql_data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave 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:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
1 row in set (0.00 sec)
970

被折叠的 条评论
为什么被折叠?



