基础知识:
需求:
最初只有主数据库,这样即使有数据备份,对业务保证也不够高(业务不大,不需要做主主)。所以新增一台数据库备用服务器,做主从复制。
准备:
在master数据库服务器的操作添加用于复制的用户
grant replication client,replication slave on *.* to 'angus'@'%.%.%.%' identified by 'password';
修改server id (只要主从server id不一样就行,可以再从服务器该。)
开启binary logging(一般都开启过)
在slaver数据库服务器的操作
修改server id
开启relay-log
开启binary logging(主从切换 做准备)
操作:
1,在从服务器上配置好数据库,最后和主数据库是一个版本。
2,sed -i '/^server-id/s#1#2#g' /etc/my.cnf
3,开启relay-log 在/etc/my.cnf 的[mysqld]区域添加下面代码
relay-log=relay-bin
relay-log=relay-bin.index
sed -i '/^server-id/a\relay-log=relay-bin\nrelay-log=relay-bin.index' /etc/my.cnf
4,对主数据进行一次完全备份
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.66 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> flush tables with read lock;
Que