Mysql主從復制操作筆記
1.先建立一個用來copy 用戶,用於從mysql從主mysql 拉進日誌.
create user copy identified by ‘123456‘;
2.給copy 用戶授權;
grant replication slave on . to ‘copy‘@‘%‘ identified by ‘123456‘;
3.手動同步主數據到從服務器上,並確保統一;
利用mysqlpump,mysqldump,xtrabackup都可以. (改天把步驟補上)
4.配置主從mysql的配置文件
主:[mysqld]
server-id = 10 #全局唯一 ID
log-bin = /data/mysql/binlog/mysql-bin #二進制文件保存路徑
從: [mysqld]
server-id = 20 #全局唯一 ID
5.查詢並記錄下主mysql的position值
mysql> show master status \g;
+----------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------+----------+--------------+------------------+-------------------+
+----------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
6.mysql> change master to master_host=‘192.168.61.130‘, master_port=3306, master_user=‘copy‘,master_password=’123456’,master_log_file=‘bin-log.000001‘, master_log_pos=154,master_connect_retry=30;
7.測試
A.在主mysql 新建一個數據庫和新建一個用戶:
mysql>create database JBB;
mysql>create user JBB;
B.在從Mysql上查詢,看JBB數據庫和JBB用戶是否已經同步到位:
mysql> show databases;
+-----------+
| user |
+-----------+
| JBB |
| mysql.sys |
| root |
+-----------+
3 rows in set (0.00 sec)
mysql> select user from mysql.user;
+-----------+
| user |
+-----------+
| JBB |
| mysql.sys |
| root |
+-----------+
3 rows in set (0.00 sec)
可以看到slave上已經可以實現主庫的同步.
Mysql主從復制操作筆記