MySQL的主从复制2

一、保持多台数据库服务器的数据同步
支持语句复制、行复制、混合复制(mixed)
built-in
高可用,负载均衡
一个从服务器只能有一个主服务器,一个主能有多个从。
异步,滞后,半同步(谷歌插件)
filter过滤
 
案例:
主从架构
 
主:
[mysqld]
vim my.cnf
log-bin = master-bin
log-bin-index = master-bin.index
server-id = 1
 
授权:
mysql>GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO repl@'192.168.0.%' IDENTIFIED BY 'password';
mysql>FLUSH PRIVILEGES;
 
从:
[mysqld]
server-id = 2
relay-log-index = slave-relay-bin.index
relay-log = slave-relay-bin
 
 
mysql>CHANGE MASTER TO MASTER_HOST='server1',MASTER_USER='repl',MASTER_PASSWORD='password',MASTER_LOG_FILE='master-bin.000001',MASTER_LOG_POS=106;
注意:重启之后要重新指一下
mysql>START SLAVE;
mysql>SHOW PROCESSLIST;
 
 
wget mysql-5.1.50-linux-i686-glibc23.tar.gz
mkdir /mydata
tar xvf mysql-5.1.50-linux-i686-glibc23.tar.gz -C /usr/local
cd /usr/local/
ln -sv mysql-5.1.50-linux-i686-glibc23 mysql
cd mysql
useradd -u 3306 -M mysql
finger mysql或id mysql
chown -R mysql:mysql .
scripts/mysql_install_db --help
scripts/mysql_install_db --user=mysql --datadir=/mydata
chown -R root .
cd support-files/
cp mysql.server /etc/init.d/mysqld
cp my-medium.cnf /etc/my.cnf
vim /etc/my.cnf 
chkconfig --add mysqld
service mysqld start
vim /etc/profile PATH=$PAHT:/usr/local/mysql/bin
. /etc/profile
 
 
二、主从备份
mysql>STOP SLAVE;
SHOW SLAVE STATUS\G
 
FLUSH TABLES WITH READ LOCK;
FLUSH LOGS;
mysqldump -uroot --all-databases --master-data=2 > /root/mysql.sql
UNLOCK TABLES;
scp mysql.sql 从:/root
 
从:
mysql -uroot < mysql.sql
 
 
三、数据库过滤:主服务器端定义从服务器能同步哪些数据库(mysql白名单、黑名单)
主:
[mysqld]
binlog-do-db mysql 仅复制
binlog-ignore-db=testdb 仅不准复制
 
 
建议在从服务器上做:
replicate-do-db = mydb 仅复制mydb
replicate-ignore-db
 
replicate-ignore-table
replicate-do-table
 
replicate-wild-do-table = catidb.rra 仅复制rra表
replicate-wild-ignore-table
 
 
四、加密方式进行复制
主从服务器端都需要证书,证书尽量不要一样
mysql>GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO repl@'192.168.0.%' IDENTIFIED BY 'password' 。。。;
mysql>FLUSH PRIVILEGES;
MASTER_SSL=1,
MASTER_SSL_CA='',
MASTER_SSL_CERT='',
MASTER_SSL_KEY='';
 
mysql P308  主--主
 
面试上机:配置lamp,mysql复制
 
 
五、主主复制
两台
 
 
六、层级复制(Master-Relay)
SET GLOBAL STORAGE_ENGINE='BLACKHOLE';
SHOW TABLES FROM mydb;
SET SQL_LOG_BIN=0;
ALTER TABLE use_data ENGINE='BLACKHOLE';
 

你可能感兴趣的:(数据库,mysql,二进制,日志,休闲)