[mysqld1]
#skip-grant-tables
user=mysql
pid-file=/var/lib/mysql3307/mysql1db.pid
port=3307
socket=/var/lib/mysql3307/mysql3307.sock
datadir=/var/lib/mysql3307/
log-error=/var/log/mysql1.log
log-bin
expire_logs_days=7
server_id=1
[mysqld2]
#skip-grant-tables
user=mysql
pid-file=/var/lib/mysql3308/mysql2db.pid
port=3308
socket=/var/lib/mysql3308/mysql3308.sock
datadir=/var/lib/mysql3308/
log-error=/var/log/mysql2.log
server_id=2
[mysqld3]
#skip-grant-tables
user=mysql
pid-file=/var/lib/mysql3309/mysql3db.pid
port=3309
socket=/var/lib/mysql3309/mysql3309.sock
datadir=/var/lib/mysql3309/
log-error=/var/log/mysql3.log
server_id=3
[mysqld4]
#skip-grant-tables
user=mysql
pid-file=/var/lib/mysql3310/mysql4db.pid
port=3310
socket=/var/lib/mysql3310/mysql3310.sock
datadir=/var/lib/mysql3310/
log-error=/var/log/mysql4.log
server_id=4
[root@mysqldb mysql_sql]# netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:55602 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 ::1:631 :::* LISTEN
tcp 0 0 :::3306 :::* LISTEN
tcp 0 0 :::3307 :::* LISTEN
tcp 0 0 :::3308 :::* LISTEN
tcp 0 0 :::3309 :::* LISTEN
tcp 0 0 :::111 :::* LISTEN
tcp 0 0 :::55761 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
[root@mysqldb mysql_sql]#
看到 我们指定的3307,3308,3309 对应的就是三个实例 mysql1 mysql2 mysql3
分别开三个终端,登录数据库
mysql -u root -p -h 127.0.0.1 -P 3307 | 3308
登录好以后
查看主库信息选择从哪个点开始同步:
mysql> show master status;
+---------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------------+----------+--------------+------------------+-------------------+
| mysql1db-bin.000008 | 858 | | | |
+---------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
配置 主库:
创建一个用户具有REPLICATION SLAVE 权限。
grant REPLICATION SLAVE on *.* to slave@127.0.0.1 identified by '123';
配置 备库:
change master to
master_host='127.0.0.1', --主数据库机
master_port=3307, --主实例端口
master_user='salve', --主数据库创建的给=从库用的用户
master_password='123', --密码
master_log_file='mysql1db-bin.000008',
master_log_pos=120;
说明:从mysql1db-bin.000008 这个日志文件的120 pos 点开始应用,
备库配置好以后启动同步:
mysql> start slave ;
Query OK, 0 rows affected, 1 warning (0.00 sec)
Note (Code 1254): Slave is already running
查看备库是否同步:
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 127.0.0.1
Master_User: salve
Master_Port: 3307
Connect_Retry: 60
Master_Log_File: mysql1db-bin.000008
Read_Master_Log_Pos: 858
Relay_Log_File: mysql3db-relay-bin.000002
Relay_Log_Pos: 1024
Relay_Master_Log_File: mysql1db-bin.000008
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: 858
Relay_Log_Space: 1200
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: 1
Master_UUID: ac096fe9-6e33-11e4-96cd-000c2947db3a
Master_Info_File: /var/lib/mysql3309/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
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
1 row in set (0.00 sec)