-----------------------------------------------------------
mysql 5.5 环境用的数据库可的多实例
-----------------------------------------------------------
mysql 主从复制原理图

mysql 主从复制开始配置 环境是一个数据库多个实例 3306端口为主 3307端口为从
1 开始配置主库和从库的my.cnf配置文件
配置主数据库的my.cnf文件(3306)
server-id = 1
log-bin=mysql-bin
配置从数据库的my.cnf文件(3307)
server-id = 2
#log-bin=mysql-bin
然后重启数据库
2登录主数据库给从数据库分配权限用户
grant replication slave on *.* to 'repl'@'192.168.1.17' identified by '123456';
3 锁表并且导出主库里的数据
flush table with read lock;
show master status;查看bin-log的位置状态
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000009 | 264 | | |
+------------------+----------+--------------+------------------+
/usr/local/mysql/bin/mysqldump -uroot -plampol -S /tmp/mysql3306.sock --events -A -B > /tmp/master.sql;
4 进从数据库导入主数据库的数据
source /tmp/master.sql
5进从库执行
change master to master_host='192.168.1.17',
master_port=3306,
master_user='repl',
master_password='123456',
master_log_file='mysql-bin.000009',
master_log_pos=264;
6 从库开启同步开关 start slave