首页 > 运维 > linux运维 > 正文

MySQL基于GTID主从复制入门

爱谁谁
发布: 2025-07-19 09:54:27
原创
588人浏览过

mysql复制架构的详细配置和设置过程如下:

MySQL基于GTID主从复制入门

Master节点配置与初始化:

Master节点的配置文件如下:

[client]
port = 3306
socket = /tmp/master-mysql.sock
<p>[mysql]
no-auto-rehash</p><p>[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
user = mysql
port = 3306
socket  = /tmp/master-mysql.sock
server-id=1
port=3306
datadir=/data1/mysql/master/data
log_error=/data1/mysql/master/log/master.log
pid_file=/data1/mysql/master/data/mysql.pid
server_id=101
gtid_mode=on
enforce_gtid_consistency=on
log_bin=master-binlog
log-slave-updates=1
binlog_format=row
skip_slave_start=1
max_connect_errors=1000
登录后复制

Master节点的数据库初始化命令:

mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data1/mysql/master/data
登录后复制

Master节点数据库启动命令:

nohup mysqld_safe --defaults-file=/data1/my-master.cnf > master.log 2>&1 &
登录后复制

Slave节点配置与初始化:

Slave节点的配置文件如下:

[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
user = mysql
port = 3307
socket  = /tmp/slave-mysql.sock
datadir=/data1/mysql/slave/data
log-error = /data1/mysql/slave/log/slave.log
pid-file = /data1/mysql/slave/data/slave.pid
max_connect_errors=1000
gtid_mode=on
enforce_gtid_consistency=on
server_id=102
log-bin=slave-binlog
log-slave-updates=1
binlog_format=row
skip_slave_start=1
登录后复制

Slave数据库初始化命令:

mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data1/mysql/slave/data
登录后复制

Slave节点数据库启动命令:

小门道AI
小门道AI

小门道AI是一个提供AI服务的网站

小门道AI117
查看详情 小门道AI
nohup mysqld_safe --defaults-file=/data1/my-slave.cnf > slave.log 2>&1 &
登录后复制

MySQL基于GTID主从复制入门

主从节点创建超级用户:

在Master节点上创建超级用户:

[perrynzhou@debian /data1]$ mysql -uroot -P 3306 -S /tmp/master-mysql.sock
mysql> create user 'admin'@'%' identified by 'admin';
mysql> grant all privileges on <em>.</em> to 'admin'@'%';
mysql> flush privileges;
登录后复制

GTID复制配置:

在主节点上创建复制用户:

[perrynzhou@debian /data1]$ mysql -uroot -P 3306 -S /tmp/master-mysql.sock
mysql> create user 'repl'@'%' identified by 'repl';
mysql> grant replication slave,replication client on <em>.</em> to 'repl'@'%';
mysql> flush privileges;
登录后复制

在Slave节点上验证Master节点的复制用户:

mysql -urepl -prepl -h127.0.0.1 -P 3306
登录后复制

在Slave节点上配置主从复制:

[perrynzhou@debian /data1]$ mysql -uroot -S /tmp/slave-mysql.sock -P 3307 -p
mysql> change master to master_host='127.0.0.1', master_user='repl', master_password='repl', master_port=3306, master_auto_position=1;
mysql> start slave;
登录后复制

查看Slave节点的复制状态:

mysql> show slave status\G
<strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><em> 1. row </em></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong>
Slave_IO_State: Waiting for master to send event
Master_Host: 127.0.0.1
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-binlog.000007
Read_Master_Log_Pos: 3452
Relay_Log_File: debian-relay-bin.000006
Relay_Log_Pos: 470
Relay_Master_Log_File: master-binlog.000007
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: 3452
Relay_Log_Space: 994
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: 101
Master_UUID: 6443e6e9-bb9c-11eb-bee9-001c420bbbe1
Master_Info_File: mysql.slave_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: 6443e6e9-bb9c-11eb-bee9-001c420bbbe1:1-13
Executed_Gtid_Set: 6443e6e9-bb9c-11eb-bee9-001c420bbbe1:1-13,77c34ad3-bb9e-11eb-b695-001c420bbbe1:1-17
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.02 sec)
登录后复制

以上就是MySQL基于GTID主从复制入门的详细内容,更多请关注php中文网其它相关文章!

相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号