Mysql双机热备主从配置
2015-06-30 13:37
621 查看
replication on mysql:
Master/Slave.
Master server is the production MySQL instance.
Slave server is the java host (123.57.39.*).
First we need to install MySQL server and client on the java host(123.57.39.*).
1.in master execute:
CREATE USER 'replica'@'123.57.39.*' IDENTIFIED BY 'replica@123';
GRANT REPLICATION SLAVE ON *.* TO 'replica'@'123.57.39.*';
flush privileges;
2.
add the following to [mysqld] segment in /etc/my.cnf of master DB. And make sure mysql user is the owner of log-bin direcotry. Otherwise you
will get error when you startup MySQL.
server-id=1
log-bin=/var/lib/mysql/binlog/mysql-bin
expire_logs_days=7
3.
On Slave,add the following to [mysqld] segment in /etc/my.cnf
server-id=2
innodb_flush_log_at_trx_commit=2 //this line is not required,just improve innodb performance
expire_logs_days=7
4.in master,then copy data to slave
mysqldump --master-data=2 --user=root --password=fadfafafaD --single-transaction --all-databases > replica.sql
5.copy the replica.sql to slave server,then import data in slave.
mysql --user=root --password=fadfafafaD < replica.sql
6.change master settting on slave;view the privious replica.sql,using "more replica.sql",you will see some text like the follwing,
-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=107;
record the red font part,then fill them into the following statement,then execute the following statement in slave mysql server.
CHANGE MASTER TO
MASTER_HOST = '123.57.38.*',
MASTER_USER = 'replica',
MASTER_PASSWORD = 'replica@123',
MASTER_LOG_FILE = 'mysql-bin.000001',
MASTER_LOG_POS = 107;
7.finally start slave;
Be don't forget to issue "show slave status\G' to check whether slave runs normally.
Master/Slave.
Master server is the production MySQL instance.
Slave server is the java host (123.57.39.*).
First we need to install MySQL server and client on the java host(123.57.39.*).
1.in master execute:
CREATE USER 'replica'@'123.57.39.*' IDENTIFIED BY 'replica@123';
GRANT REPLICATION SLAVE ON *.* TO 'replica'@'123.57.39.*';
flush privileges;
2.
add the following to [mysqld] segment in /etc/my.cnf of master DB. And make sure mysql user is the owner of log-bin direcotry. Otherwise you
will get error when you startup MySQL.
server-id=1
log-bin=/var/lib/mysql/binlog/mysql-bin
expire_logs_days=7
3.
On Slave,add the following to [mysqld] segment in /etc/my.cnf
server-id=2
innodb_flush_log_at_trx_commit=2 //this line is not required,just improve innodb performance
expire_logs_days=7
4.in master,then copy data to slave
mysqldump --master-data=2 --user=root --password=fadfafafaD --single-transaction --all-databases > replica.sql
5.copy the replica.sql to slave server,then import data in slave.
mysql --user=root --password=fadfafafaD < replica.sql
6.change master settting on slave;view the privious replica.sql,using "more replica.sql",you will see some text like the follwing,
-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=107;
record the red font part,then fill them into the following statement,then execute the following statement in slave mysql server.
CHANGE MASTER TO
MASTER_HOST = '123.57.38.*',
MASTER_USER = 'replica',
MASTER_PASSWORD = 'replica@123',
MASTER_LOG_FILE = 'mysql-bin.000001',
MASTER_LOG_POS = 107;
7.finally start slave;
Be don't forget to issue "show slave status\G' to check whether slave runs normally.
相关文章推荐
- MySQL日期数据类型、时间类型使用总结
- mysql模糊查询
- MySQL数据库主从同步
- MySQL优化之COUNT(*)效率
- mysql权限审核2
- MySQL Profiling
- 在Ubuntu或Debian系统的服务器上卸载MySQL的方法
- Navicat for mysql连接数据库 出现1130错误
- mysql 中 unix_timestamp和from_unixtime 时间戳函数
- 61 mysql csv导入数据
- MySQL操作汇总[转]
- mysql5.5复制环境中的一个bug
- 为MYSQL加密码
- MySQL DATE_ADD() 函数
- MySQL内存分配
- mysql 5.1以后支持任务计划event_schedule
- EntityFramework+MySql 笔记2
- sql语句 union mysql
- EntityFramework+MySql 笔记1
- mysql的锁表问题