mysql主从

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
云数据库 RDS PostgreSQL,高可用系列 2核4GB
简介:

一、实验环境
1、IP与主机名
192.168.10.51   db1.linuxbrother.com master
192.168.10.52 db2.linuxbrother.com slave
2、所需软件
mysql-5.1.63.tar.gz
3、安装gcc和相应的依赖包
[root@db1 ~]# yum -y install gcc ncurses-devel libtool
二、Master配置
1、安装Mysql
[root@db1 ~]# tar -zxvf mysql-5.1.63.tar.gz -C /usr/src/
[root@db1 ~]# useradd -M -s /sbin/nologin mysql
[root@db1 ~]# cd /usr/src/mysql-5.1.63/
[root@db1 mysql-5.1.63]# vim configure   #把下面行注释掉
52297 #    $RM "$cfgfile"
[root@db1 mysql-5.1.63]# ./configure --prefix=/usr/local/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase --with-mysqld-user=mysql
[root@db1 mysql-5.1.63]# make
[root@db1 mysql-5.1.63]# make install
[root@db1 mysql-5.1.63]# cp support-files/my-medium.cnf /usr/local/mysql/my.cnf
[root@db1 mysql-5.1.63]# /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data 
[root@db1 mysql-5.1.63]# chown -R root.mysql /usr/local/mysql
[root@db1 mysql-5.1.63]# chown -R mysql /usr/local/mysql/data/
[root@db1 mysql-5.1.63]# echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf  
[root@db1 mysql-5.1.63]# ldconfig 
[root@db1 mysql-5.1.63]# echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
[root@db1 mysql-5.1.63]# source /etc/profile
[root@db1 mysql-5.1.63]# mkdir /usr/local/mysql/tmp
[root@db1 mysql-5.1.63]# chmod 777 /usr/local/mysql/tmp/
[root@db1 mysql-5.1.63]# vim /usr/local/mysql/my.cnf  #修改socket位置
socket          = /usr/local/mysql/tmp/mysql.sock
[root@db1 mysql-5.1.63]# mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &
[root@db1 mysql-5.1.63]# mysql -uroot -p --socket=/usr/local/mysql/tmp/mysql.sock 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.63-log Source distribution

Copyright (c) 2000, 2011, 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 'backup'@'192.168.10.52' identified by 'backuppwd';
Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000002 |      265 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
三、Slave配置
安装过程如上,步骤省略......
[root@db2 mysql-5.1.63]# vim /usr/local/mysql/my.cnf   #修改server-id
server-id       = 2
[root@db2 mysql-5.1.63]# mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &
[root@db2 mysql-5.1.63]# mysql -uroot -p --socket=/usr/local/mysql/tmp/mysql.sock 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.63-log Source distribution

Copyright (c) 2000, 2011, 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> change master to master_host='192.168.10.51',master_user='backup',master_password='backuppwd',master_log_file='mysql-bin.000002',master_log_pos=265;
Query OK, 0 rows affected (0.24 sec)

mysql> start slave;
Query OK, 0 rows affected (0.02 sec)

mysql> show slave status\G
......
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
......
四、验证
1、在Master上面操作
[root@db1 mysql-5.1.63]# mysql -uroot -p --socket=/usr/local/mysql/tmp/mysql.sock 
mysql> create database mysqltest;
Query OK, 1 row affected (0.00 sec)

mysql> use mysqltest;
Database changed
mysql> create table user (id int(5),name char(10));
Query OK, 0 rows affected (0.00 sec)

mysql> insert into user values (0001,'xieping');
Query OK, 1 row affected (0.00 sec)

mysql> insert into user values (0002,'huxinxin');
Query OK, 1 row affected (0.00 sec)

mysql> insert into user values (0003,'dingpeng');
Query OK, 1 row affected (0.00 sec)
2、在Slave上操作
[root@db2 mysql-5.1.63]# mysql -uroot -p --socket=/usr/local/mysql/tmp/mysql.sock 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| mysqltest          |
| test               |
+--------------------+
4 rows in set (0.02 sec)

mysql> select id,name from mysqltest.user;
+------+----------+
| id   | name     |
+------+----------+
|    1 | xieping  |
|    2 | huxinxin |
|    3 | dingpeng |
+------+----------+
3 rows in set (0.00 sec)














本文转自谢无赖51CTO博客,原文链接:http://blog.51cto.com/xieping/925377 ,如需转载请自行联系原作者




相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
关系型数据库 MySQL 开发工具
MySQL5.7主从配置(Docker)
MySQL5.7主从配置(Docker)
881 0
|
Ubuntu 关系型数据库 MySQL
使用Ubuntu和Windows电脑实现Mysql主从同步(详细操作步骤)
使用Ubuntu和Windows电脑实现Mysql主从同步(详细操作步骤)
165 2
|
SQL 关系型数据库 MySQL
解决MySQL主从慢同步问题的常见的解决方案:
解决MySQL主从慢同步问题的方法有很多,以下是一些常见的解决方案: 1. 检查网络连接:确保主从服务器之间的网络连接稳定,避免网络延迟或丢包导致数据同步缓慢。 2. 优化数据库配置:调整MySQL的配置参数,如增大binlog文件大小、调整innodb_flush_log_at_trx_commit等参数,以提高主从同步性能。 3. 检查IO线程和SQL线程状态:通过SHOW SLAVE STATUS命令检查IO线程和SQL线程的状态,确保它们正常运行并没有出现错误。 4. 检查主从日志位置:确认主从服务器的binlog文件和位置是否正确,避免由于错误的日志位置导致同步延迟。 5.
1545 1
|
Kubernetes Cloud Native 关系型数据库
提升数据安全与性能,掌握Helm一键部署MySQL 8.0主从技巧
【4月更文挑战第9天】提升数据安全与性能,掌握Helm一键部署MySQL 8.0主从技巧
615 0
|
SQL 存储 关系型数据库
MySQL的主从复制&主从同步
MySQL的主从复制&主从同步
211 0
|
负载均衡 关系型数据库 MySQL
MySQL主从架构的搭建
MySQL主从架构的搭建
172 3
|
SQL 关系型数据库 MySQL
MySQL-主从架构的搭建
MySQL-主从架构的搭建
344 0
|
11月前
|
Prometheus 监控 关系型数据库
数据库同步革命:MySQL GTID模式下主从配置的全面解析
数据库同步革命:MySQL GTID模式下主从配置的全面解析
1037 0
|
10月前
|
存储 关系型数据库 MySQL
利用 MySQL 克隆插件搭建主从
MySQL 的 Clone 插件是一个强大的功能,首次引入于 MySQL 8.0.17 版本。简单来说,Clone Plugin 是一款物理克隆数据工具,它能够帮助我们快速、高效地克隆或复制数据库,极大地简化了数据库迁移、备份和恢复的过程,让我们在处理大量数据时更加得心应手。本篇文章我们一起来学习下如何使用克隆插件。
140 2
|
10月前
|
运维 关系型数据库 MySQL
【实操记录】MySQL主从配置
本文使用MySQL原生支持的主从同步机制,详细记录了配置步骤及运维操作方法,可供大家直接参考、使用。 本文假设已经部署了两台主机的MySQL软件,且数据库服务正常,详细部署步骤可本站搜索:"mysql二进制安装包部署"
533 0