|NO.Z.00095|——————————|^^ 部署 ^^|——|Linux&MySQL集群.V03|——|一主多从|

一、mysql一主多从:主服务器配置
### --- 部署规划;在原来基础之上部署

~~~		centos6.x server1:20.20.20.21           // 主
~~~		centos6.x server2:20.20.20.22           // 从
~~~		centos6.x server3:20.20.20.23           // 从
### --- 环境准备:
~~~		centos6.x server1: 为主
~~~		把centos6.x server1 的从停掉

mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
### --- 配置从服务器centos6.x server23

[root@server23 ~]# yum install -y mysql-server mysql
[root@server23 ~]# vim /etc/my.cnf 
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-bin=mysql-bin
server-id=23
#replicate-do-db=test
binlog-ignore-db=mysql
###binlog-ignore-db=information_schema
###auto-increment-increment=2
###auto-increment-offset=1

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
### --- 授权23为从服务器

[root@server23 ~]# service mysqld start
### --- 在21主服务器上授权

mysql> grant replication slave on *.* to slave@'20.20.20.23' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000004 |      338 |              | mysql            |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
### --- 从服务器23接收授权

mysql> change master to master_user='slave',master_password='123456',master_host='20.20.20.21',master_log_file='mysql-bin.000004',master_log_pos=338;
Query OK, 0 rows affected (0.07 sec)
二、验证测试
### --- 在主服务器上创建a1数据库

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)
mysql> create database a111 ;
Query OK, 1 row affected (0.00 sec)
### --- 第一个22从服务器查看是否创建a111数据库

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| a111               |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)
### --- 第二个23从服务器查看是否创建a111数据库

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| a111               |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(6)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示