網上有不少資料,可是mysql版本更新會形成不少不一致下面是個人操做流程;mysql
第一步安裝主mysqlsql
配置my.ini服務器
log_bin=D:\Mysql\mysql-5.7.17-winx64-master\log-bin //二進制日誌,主從配置必需要在主服務器上配置
log_error=D:\Mysql\mysql-5.7.17-winx64-master\log-error //查看錯誤,須要用到
general_log=ON //5.7須要這樣配置
general_log_file=D:\Mysql\mysql-5.7.17-winx64-master\log
slow_query_log=ON
slow_query_log_file=D:\Mysql\mysql-5.7.17-winx64-master\log-slow
binlog_ignore_db=mysql //不一樣步的庫
basedir =D:\Mysql\mysql-5.7.17-winx64-master
datadir =D:\Mysql\mysql-5.7.17-winx64-master\data
port =3306
server_id =1 //主從服務器這個值必定不能相同
ide
進入D:\Mysql\mysql-5.7.17-winx64-master\binui
mysqld--initialize //5.7須要先執行會初始化data目錄spa
mysqld install mysql-master日誌
第二步安裝從mysqlserver
配置my.iniip
log_error=D:\Mysql\mysql-5.7.17-winx64-master\log-error
general_log=ON
general_log_file=D:\Mysql\mysql-5.7.17-winx64-master\log
slow_query_log=ON
slow_query_log_file=D:\Mysql\mysql-5.7.17-winx64-master\log-slow
basedir =D:\Mysql\mysql-5.7.17-winx64-slave
datadir =D:\Mysql\mysql-5.7.17-winx64-slave\data
port =3307
server_id =2同步
直接copy主服務的data目錄到從服務器下,這裏會形成一個問題
須要修改data\auto.cnf 的service-uuid的值否則會形成主從失敗
進入D:\Mysql\mysql-5.7.17-winx64-slave\bin
mysqld install mysql-slave
第三步配置主從
依次啓動服務器
在主mysql中建立用戶slave
create user 'slave'@'127.0.0.1' identified by 'slave';
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'127.0.0.1';//分配權限
show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 107 | test | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
在從服務器中執行
change master to master_host='127.0.0.1',master_port=3306,master_user='salve',master_password='salve',master_log_file='mysql-bin.000001',master_log_pos=107;
Query OK, 0 rows affected (0.19 sec)
start slave;
查看slave狀態
show slave status;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.17.2.40
Master_User: photorepl
Master_Port: 4331
Connect_Retry: 60
Master_Log_File: mysql-bin.005502
Read_Master_Log_Pos: 64401238
Relay_Log_File: mysqld-relay-bin.015418
Relay_Log_Pos: 13456757
Relay_Master_Log_File: mysql-bin.005152
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB: mysql
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table: photo.%
Replicate_Wild_Ignore_Table: mysql.%
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 13456620
Relay_Log_Space: 36764898503
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: 249904
××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
只要這兩個是yes就對咯;