博客
关于我
linux的mysql主主_Mysql主主
阅读量:808 次
发布时间:2023-02-04

本文共 2015 字,大约阅读时间需要 6 分钟。

MySQL主从服务器配置与数据库同步指南

1. 创建同步用户

在主服务器(ODD)上执行以下命令:

mysql> grant replication slave on *.* to 'water'@'192.168.1.115' identified by 'cdio2010';

在从服务器(EVEN)上执行以下命令:

mysql> grant replication slave on *.* to 'water'@'192.168.1.116' identified by 'cdio2010';

复制完成后执行以下命令:

mysql> flush privileges;

2. 修改MySQL配置文件

在主服务器(ODD)上:

[mysqld]binlog-do-db=db_rockybinlog-ignore-db=mysqlreplicate-do-db=db_rockyreplicate-ignore-db=mysql,information_schemalog-slave-updates=1sync_binlog=1auto_increment_offset=1auto_increment_increment=2slave-skip-errors=all

在从服务器(EVEN)上:

[mysqld]server-id=2binlog-do-db=db_rockybinlog-ignore-db=mysqlreplicate-do-db=db_rockyreplicate-ignore-db=mysql,information_schemalog-slave-updates=1sync_binlog=1auto_increment_offset=2auto_increment_increment=2slave-skip-errors=all

3. 重启MySQL服务

在主服务器(ODD)和从服务器(EVEN)上执行以下命令:

sudo systemctl restart mysql

4. 查看主服务器状态

在主服务器(ODD)上:

mysql> flush tables with read lock;mysql> show master status\G;

在从服务器(EVEN)上:

mysql> flush tables with read lock;mysql> show master status\G;

5. 设置同步位置

在主服务器(ODD)上执行以下命令:

mysql> change master to master_host='192.168.1.115', master_user='water', master_password='cdio2010', \master_log_file='mysql-bin.000008', master_log_pos=107;

在从服务器(EVEN)上执行以下命令:

mysql> change master to master_host='192.168.1.116', master_user='water', master_password='cdio2010', \master_log_file='mysql-bin.000007', master_log_pos=438;

6. 重启服务并检查状态

在主服务器(ODD)和从服务器(EVEN)上重启服务:

sudo systemctl restart mysql

查看从服务器状态:

mysql> show slave status\G;

7. 测试数据库同步

在从服务器(EVEN)上:

mysql> show databases;

查看数据库列表:

+--------------------+| Database | +--------------------+| information_schema | | db_rocky | | mysql | | performance_schema | | test | +--------------------+

创建表并插入数据:

mysql> use db_rocky;mysql> create table water (id int);mysql> insert into water values(1);mysql> commit;

在主服务器(ODD)上验证:

mysql> show tables;mysql> select * from water;

8. 检查从服务器状态

在主服务器(ODD)和从服务器(EVEN)上执行以下命令:

mysql> show slave status\G;

主要关注参数:

  • Slave_IO_Running: Yes
  • Slave_SQL_Running: Yes

转载地址:http://mpkfk.baihongyu.com/

你可能感兴趣的文章
Python 中的range(),arange()函数
查看>>
Python 中的内存管理机制
查看>>
Python 中的函数包装器:模型运行时和调试
查看>>
Python 中的列表理解和 lambda
查看>>
Python 中的多层for in嵌套循环使用
查看>>
Python 中的多线程(01/4)
查看>>
Python 中的多进程(01/2):简介
查看>>
Python 中的多进程(02/2):进程之间的通信)
查看>>
Python 中的字符串、列表、元组和字典数据类型的特点和使用场景
查看>>
Python 中的属性访问器是什么?如何使用 @property 装饰器?
查看>>
Python 中的带宽限制
查看>>
Python 中的机器学习简介:多项式回归
查看>>
python读取grib2数据_用Python加载grib2文件
查看>>
Python 中的注意点_s2
查看>>
Python读取Excel的几种工具包(附Demo)
查看>>
Python 中的生成器是什么?
查看>>
Python 中的离线语音转文本
查看>>
Python读写json文件的简单实现
查看>>
Python 中的线程
查看>>
Python 中的继承机制是什么样的?
查看>>