Mysql Master-slave複製簡單配置記錄
搭建了一下mysql master slave的環境
在此做一下簡單記錄
mysql資料庫版本:5.7-18
master與slave均採用瞭如下方式初始化mysql資料庫
mkdir -p /data/mysql
useradd mysql
chown -R mysql:mysql /data/
chown -R mysql:mysql /usr/local/mysql*
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --datadir=/data/mysql/ --user=mysql --initialize-insecure
Master的my.cnf配置:
點選(此處)摺疊或開啟
- [client]
- port = 3306
- socket = /tmp/mysql.sock
- #default-character-set=utf8
- [mysql]
- #default-character-set=utf8
- [mysqld]
- port = 3306
- socket = /tmp/mysql.sock
- basedir = /usr/local/mysql
- datadir = /data/mysql
- server_id=151
- open_files_limit = 3072
- back_log = 103
- max_connections = 512
- max_connect_errors = 100000
- table_open_cache = 512
- external-locking = FALSE
- max_allowed_packet = 128M
- sort_buffer_size = 2M
- join_buffer_size = 2M
- thread_cache_size = 51
- query_cache_size = 32M
- tmp_table_size = 96M
- max_heap_table_size = 96M
- slow_query_log = 1
- slow_query_log_file = /data/mysql/slow.log
- log-error = /data/mysql/error.log
- long_query_time = 0.05
- log-bin = /data/mysql/mysql-bin
- sync_binlog = 1
- binlog_cache_size = 4M
- max_binlog_cache_size = 128M
- max_binlog_size = 1024M
- expire_logs_days = 7
- key_buffer_size = 32M
- read_buffer_size = 1M
- read_rnd_buffer_size = 16M
- bulk_insert_buffer_size = 64M
- character-set-server=utf8
- default-storage-engine=InnoDB
- binlog_format=row
- #gtid_mode=on
- #log_slave_updates=1
- #enforce_gtid_consistency=1
- interactive_timeout=100
- wait_timeout=100
- transaction_isolation = REPEATABLE-READ
- #innodb_additional_mem_pool_size = 16M
- innodb_buffer_pool_size = 1434M
- innodb_data_file_path = ibdata1:1024M:autoextend
- innodb_flush_log_at_trx_commit = 1
- innodb_log_buffer_size = 16M
- innodb_log_file_size = 256M
- innodb_log_files_in_group = 2
- innodb_max_dirty_pages_pct = 50
- innodb_file_per_table = 1
- innodb_locks_unsafe_for_binlog = 0
- [mysqldump]
- quick
- max_allowed_packet = 32M
Slave的配置檔案:/etc/my.cnf
點選(此處)摺疊或開啟
- [client]
- port = 3306
- socket = /tmp/mysql.sock
- #default-character-set=utf8
- [mysql]
- #default-character-set=utf8
- [mysqld]
- port = 3306
- socket = /tmp/mysql.sock
- basedir = /usr/local/mysql
- datadir = /data/mysql
- server_id=152
- #master slave replicat
- #master-host=192.168.43.151
- #master-user=repl
- #master-password=repl
- relay-log=/data/mysql/mysql-replay-bin
- master-info-file = /data/mysql/mysql-master.info
- relay-log-info-file = /data/mysql/mysql-relay-log.info
- open_files_limit = 3072
- back_log = 103
- max_connections = 512
- max_connect_errors = 100000
- table_open_cache = 512
- external-locking = FALSE
- max_allowed_packet = 128M
- sort_buffer_size = 2M
- join_buffer_size = 2M
- thread_cache_size = 51
- query_cache_size = 32M
- tmp_table_size = 96M
- max_heap_table_size = 96M
- slow_query_log = 1
- slow_query_log_file = /data/mysql/slow.log
- log-error = /data/mysql/error.log
- long_query_time = 0.05
- log-bin = /data/mysql/mysql-bin
- sync_binlog = 1
- binlog_cache_size = 4M
- max_binlog_cache_size = 128M
- max_binlog_size = 1024M
- expire_logs_days = 7
- key_buffer_size = 32M
- read_buffer_size = 1M
- read_rnd_buffer_size = 16M
- bulk_insert_buffer_size = 64M
- character-set-server=utf8
- default-storage-engine=InnoDB
- binlog_format=row
- #gtid_mode=on
- #log_slave_updates=1
- #enforce_gtid_consistency=1
- interactive_timeout=100
- wait_timeout=100
- transaction_isolation = REPEATABLE-READ
- #innodb_additional_mem_pool_size = 16M
- innodb_buffer_pool_size = 1434M
- innodb_data_file_path = ibdata1:1024M:autoextend
- innodb_flush_log_at_trx_commit = 1
- innodb_log_buffer_size = 16M
- innodb_log_file_size = 256M
- innodb_log_files_in_group = 2
- innodb_max_dirty_pages_pct = 50
- innodb_file_per_table = 1
- innodb_locks_unsafe_for_binlog = 0
- [mysqldump]
- quick
- max_allowed_packet = 32M
參考:
https://blog.csdn.net/edwzhang/article/details/8819629
初始話完成之後,在master通過mysqldump匯出mysql資料庫
會話1:
[root@mysql01 ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18-log MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY 'repl';
Query OK, 0 rows affected, 1 warning (0.05 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH TABLES WITH READ LOCK;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000017 | 581 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
這個Master Status很重要,在其後的slave配置中需要依賴它
mysqldump -u root -p --all-databases --master-data > /root/dbdump.db
匯出之後,釋放鎖
mysql> unlock tables;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 5
Current database: *** NONE ***
Query OK, 0 rows affected (0.00 sec)
slave端匯入, 匯入之後重啟mysql服務
mysql -u root -p < /root/dbdump.db
在slave端啟用複製:
mysql> CHANGE MASTER TO
-> MASTER_HOST='192.168.43.151',
-> MASTER_USER='repl',
-> MASTER_PASSWORD='repl',
-> MASTER_LOG_FILE='mysql-bin.000017',
-> MASTER_LOG_POS=581;
Query OK, 0 rows affected, 2 warnings (0.30 sec)
mysql>
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
在master端進行測試:
mysql> create database test2;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 7
Current database: *** NONE ***
Query OK, 1 row affected (0.28 sec)
mysql>
mysql> show slave staus
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'staus' at line 1
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000017 | 743 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql>
mysql> use test02
No connection. Trying to reconnect...
Connection id: 8
Current database: *** NONE ***
ERROR 1049 (42000): Unknown database 'test02'
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test2 |
+--------------------+
5 rows in set (0.00 sec)
mysql> use test2
Database changed
mysql>
mysql>
mysql> create table mytest01(pid int, nme varchar(100));
Query OK, 0 rows affected (0.34 sec)
mysql>
mysql> insert into mytest01 values(1, 'AAAA');
Query OK, 1 row affected (0.04 sec)
mysql>
如果配置正確,應當可以在slave端看到資料
參考:https://blog.longwin.com.tw/2008/03/mysql_replication_master_slave_set_2008/
https://blog.wu-boy.com/2008/12/mysql-%E5%AF%A6%E5%81%9A-mysql-master-master-replication-%E5%90%8C%E6%AD%A5/
https://www.tecmint.com/how-to-setup-mysql-master-slave-replication-in-rhel-centos-fedora/
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8520577/viewspace-2156333/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Mysqldump實現mysql的master-slave主從複製MySqlAST
- 簡單搭建MySQL主從複製MySql
- mysql複製--主從複製配置MySql
- Innobackupex實現mysql線上搭建master-slave主從複製MySqlAST
- MySQL 8 複製(五)——配置GTID複製MySql
- MySQL並行複製-原始碼理解記錄MySql並行原始碼
- mysql5.5.20複製配置MySql
- 簡單實踐實現 MySQL 主從複製MySql
- MySQL 8 複製(九)——組複製聯機配置MySql
- MySQL:簡單記錄訊號處理MySql
- MySQL高可用之組複製技術(2):配置單主模型的組複製MySql模型
- MYSQL主從複製製作配置方案MySql
- MYSQL主從複製配置(整理)MySql
- MySQL8.0.11 組複製配置MySql
- MySQL:connect_timeout引數簡單記錄MySql
- list複製踩坑記錄
- MySQL:簡單記錄一下Waiting for commit lockMySqlAIMIT
- MySQL:簡單記錄刪除binary log的介面MySql
- MySQL-主從複製簡介MySql
- Centos8.3、mysql8.0主從複製實戰記錄CentOSMySql
- MySQL 主從複製安裝部署配置MySql
- Docker 教程十五配置MySQL 主從複製DockerMySql
- 5-5配置Mysql複製 基於日誌點的複製MySql
- 複製資訊記錄表|全方位認識 mysql 系統庫MySql
- MySQL主從複製配置心跳功能介紹MySql
- MySQL複製MySql
- MySQL:簡單記錄character_set_server影響引數MySqlServer
- 【實操記錄】MySQL主從配置MySql
- mysql主從複製配置與問題解決MySql
- MySQL高可用之組複製技術(3):配置多主模型的組複製MySql模型
- http報文簡單記錄HTTP
- Blender Shader Node簡單記錄
- MySQL 8 複製(三)——延遲複製與部分複製MySql
- MySQL主從複製之GTID複製MySql
- MySQL 8 複製(一)——非同步複製MySql非同步
- MySQL 8 複製(二)——半同步複製MySql
- MySQL 8 複製(四)——GTID與複製MySql
- MySQL防止重複插入相同記錄 insert if not existsMySql