赞
踩
主库IP:192.168.164.21
从库IP:192.168.164.22
事先在两台服务器上安装好mysql5.7
将一下内容覆盖到该文件中
1)首先需要修改文件中的server-id,保证唯一性,并且master库的该值一定要小于slave库
它是mysql服务的唯一标识,如果时单机模式的话不需要修改,可以时任何值,如果时集群模式,需要修改,要保证它的唯一性
2)修改log_bin 值:为master_log
日志文件命名, 开启日志功能。此日志是命令日志。就是记录主库中执行的所有的 SQL 命令的
MySQL的log_bin不是执行日志,状态日志. 是操作日志.就是在DBMS中所有的SQL命令 log_bin 日志不是必要的.只有配置主从备份时才必要
变量的值就是日志文件名称.是日志文件名称的主体. MySQL 数据库自动增加文件名后缀和文件类型.
3)保存重启mysql
- [client]
- port = 3306
- default-character-set = utf8mb4
-
- [mysqld]
- port = 3306
-
- user = mysql
- bind-address = 0.0.0.0
- server-id = 1
-
- init-connect = 'SET NAMES utf8mb4'
- character-set-server = utf8mb4
-
- skip-name-resolve
- skip-external-locking
- #skip-networking
- back_log = 300
-
- max_connections = 1000
- max_connect_errors = 6000
- open_files_limit = 65535
- table_open_cache = 128
- max_allowed_packet = 4M
- binlog_cache_size = 1M
- max_heap_table_size = 8M
- tmp_table_size = 16M
-
- read_buffer_size = 2M
- read_rnd_buffer_size = 8M
- sort_buffer_size = 8M
- join_buffer_size = 8M
- key_buffer_size = 4M
- thread_cache_size = 8
- query_cache_type = 1
- query_cache_size = 8M
- query_cache_limit = 2M
- ft_min_word_len = 4
- log_bin = master_log
- binlog_format = mixed
- expire_logs_days = 10
- slow_query_log = 1
- long_query_time = 1
- performance_schema = 0
- explicit_defaults_for_timestamp
-
- lower_case_table_names = 1
- default_storage_engine = InnoDB
- #default-storage-engine = MyISAM
- innodb_file_per_table = 1
- innodb_open_files = 500
- innodb_buffer_pool_size = 64M
- innodb_write_io_threads = 4
- innodb_read_io_threads = 4
- innodb_thread_concurrency = 0
- innodb_purge_threads = 1
- innodb_flush_log_at_trx_commit = 2
- innodb_log_buffer_size = 2M
- innodb_log_file_size = 32M
- innodb_log_files_in_group = 3
- innodb_max_dirty_pages_pct = 90
- innodb_lock_wait_timeout = 120
-
- bulk_insert_buffer_size = 8M
- myisam_sort_buffer_size = 8M
- myisam_max_sort_file_size = 10G
- myisam_repair_threads = 1
-
- interactive_timeout = 28800
- wait_timeout = 28800
-
- [mysqldump]
- quick
- max_allowed_packet = 16M
-
- [myisamchk]
- key_buffer_size = 8M
- sort_buffer_size = 8M
- read_buffer = 4M
- write_buffer = 4M

文件内容属性说明如下
- [client] mysql -uroot -proot
- port = 3306 客户端端口
- default-character-set = utf8mb4 客户端默认字符集
-
- [mysqld] 服务器
- port = 3306 端口
-
- user = mysql 提供简单用户数据
- bind-address = 0.0.0.0 当前用户可访问的主机IP, localhost. mysql用户只能在本地访问.
- server-id = 1 服务器的唯一标识
-
- init-connect = 'SET NAMES utf8mb4' 初始化数据库链接时提供的配置信息
- character-set-server = utf8mb4 服务器基本字符集
-
- skip-name-resolve
- skip-external-locking
- #skip-networking
- back_log = 300
-
- max_connections = 1000 最大客户端连接数
- max_connect_errors = 6000 单次连接最大可能出现的错误数.
- open_files_limit = 65535
- table_open_cache = 128 表的开启基础缓存. 单位是个数
- max_allowed_packet = 4M
- binlog_cache_size = 1M
- max_heap_table_size = 8M
- tmp_table_size = 16M
-
- read_buffer_size = 2M 读缓存大小
- read_rnd_buffer_size = 8M
- sort_buffer_size = 8M
- join_buffer_size = 8M
- key_buffer_size = 4M
- thread_cache_size = 8
- query_cache_type = 1
- query_cache_size = 8M
- query_cache_limit = 2M
- ft_min_word_len = 4
- log_bin = mysql-bin 日志文件名称.文件名的主体内容.mysql会自动提供后缀和文件类型.
- binlog_format = mixed
- expire_logs_days = 10
- slow_query_log = 1
- long_query_time = 1
- performance_schema = 0
- explicit_defaults_for_timestamp
-
- lower_case_table_names = 1
- default_storage_engine = InnoDB 默认数据库引擎
- #default-storage-engine = MyISAM
- innodb_file_per_table = 1
- innodb_open_files = 500
- innodb_buffer_pool_size = 64M
- innodb_write_io_threads = 4
- innodb_read_io_threads = 4
- innodb_thread_concurrency = 0
- innodb_purge_threads = 1
- innodb_flush_log_at_trx_commit = 2
- innodb_log_buffer_size = 2M
- innodb_log_file_size = 32M
- innodb_log_files_in_group = 3
- innodb_max_dirty_pages_pct = 90
- innodb_lock_wait_timeout = 120
-
- bulk_insert_buffer_size = 8M
- myisam_sort_buffer_size = 8M
- myisam_max_sort_file_size = 10G
- myisam_repair_threads = 1
-
- interactive_timeout = 28800
- wait_timeout = 28800
-
- [mysqldump] 安全提供.
- quick
- max_allowed_packet = 16M
-
- [myisamchk] 数据库额外辅助功能配置, 如缓存,索引缓存等.
- key_buffer_size = 8M
- sort_buffer_size = 8M
- read_buffer = 4M
- write_buffer = 4M
-

在 MySQL 数据库中,为不存在的用户授权,就是同步创建用户并授权. 此用户是从库访问主库使用的用户 ip 地址不能写为%. 因为主从备份中,当前创建的用户,是给从库 Slave 访问主库 Master 使用的.用户必须有指定的访问地址.不能是通用地址.
命令:grant all privileges on *.* to 'slave'@'192.168.164.22' identified by 'slave' with grant option;
flush privileges;
可以使用默认配置, 也可以注释.
主从模式要求多个 MySQL 物理名称不能相同. 即按装 MySQL 过程中 Linux 自动生成的 物理标志. 唯一物理标志命名为 uuid. 保存位置是 MySQL 数据库的数据存放位置. 默认为 /var/lib/mysql 目录中. 文件名是 auto.cnf. 修改 auto.cnf 文件中的 uuid 数据. 随意修改,不建议改变数据长度.建议改变数据内容. /var/lib/mysql/auto.cnf
需要修改的数据是依据Master信息修改的.ip是Master所在物理机IP. 用户名和密码是 Master 提供的 Slave 访问用户名和密码. 日志文件是在 Master 中查看的主库信息提供的.在 Master 中使用命令 showmasterstatus 查看日志文件名称.
命令:change master to master_host='192.168.164.21', master_user='slave', master_password='slave',master_log_file='master_log.000001';
- mysql> show slave status \G;
- *************************** 1. row ***************************
- Slave_IO_State: Waiting for master to send event
- Master_Host: 192.168.164.21
- Master_User: slave
- Master_Port: 3306
- Connect_Retry: 60
- Master_Log_File: master_log.000001
- Read_Master_Log_Pos: 154
- Relay_Log_File: job-dangdai-node-2-relay-bin.000002
- Relay_Log_Pos: 369
- Relay_Master_Log_File: master_log.000001
- 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: 154
- Relay_Log_Space: 589
- 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 最后一次错误的 IO 请求编号
- Last_IO_Error:
- Last_SQL_Errno: 0 最后一次错误的执行 SQL 命令编号
- Last_SQL_Error:
- Replicate_Ignore_Server_Ids:
- Master_Server_Id: 1
- Master_UUID: 53062ab6-b535-11e9-bd3c-000c294f0d13
- Master_Info_File: /var/lib/mysql/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.01 sec)
-
- ERROR:
- No query specified

创建表
新增一条数据
查看test_table
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。