一、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