MySQL版本:5.5.25
iptables:打开对应MySQL端口(默认port 3306)
SELinux关闭
mysql> status; //举例一个查看MySQL版本的方法
--------------
mysql Ver 14.14 Distrib 5.5.25a, for Linux (x86_64) using readline 5.1
Connection id: 485
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.25a-log MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 24 min 31 sec
Threads: 2 Questions: 52 Slow queries: 0 Opens: 16 Flush tables: 1 Open tables: 9 Queries per second avg: 0.035
--------------
mysql 主从配置(也叫AB复制),要做双主则把操作反过来再做一遍,注意在做配置期间不要有写操作。
其本身提供成熟的的主从备份机制,首先要准备两台server,分别作为master(58.64.205.132)和slave(58.64.205.133)
//1) 进入master mysql操作界面,为slave mysql授权
//若不需要进行精准授权,IP地址可使用通配符 %
mysql>grant all privileges on *.* to 'root'@'58.64.205.133' identified by '12345678';
mysql>flush privileges;
//2) 编辑master mysql的my.cnf :
# vi /etc/my.cnf
//修改(注意 master的id要与slave的不一样):
server-id=1
//接着添加需要同步的库(多个库时用,隔开):
binlog-do-db=test_db
binlog-ignore-db=mysql
//修改完成后重启master mysql:
# service mysql restart
//3) 编辑slave mysql的my.cnf:
# vi /etc/my.cnf
//修改:
server-id=2
//接着添加需要同步的库(多个库时用,隔开):
replicate-do-db=test_db
replicate-ignore-db=mysql
//修改完成后重启slave mysql:
# service mysql restart
//4)进入slave mysql操作界面,指定master相关参数
mysql>stop slave;
mysql> change master to
-> master_host='58.64.205.132',
-> master_user='root',
-> master_password='12345678',
-> master_log_file='mysql-bin.000001',
-> master_log_pos=107;
mysql> start slave;
//注意:此处的master_log_file和master_log_pos可以在master mysql查看,查看方法:进入master mysql操作界面:
mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 107
Binlog_Do_DB: test_db
Binlog_Ignore_DB: mysql
1 row in set (0.00 sec)
//查看slave mysql的状态,可以看到诸如此类信息:
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 58.64.205.132
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 107
Relay_Log_File: localhost-relay-bin.000002
Relay_Log_Pos: 253
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: test_db
Replicate_Ignore_DB: mysql
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
//注意到:
Slave_IO_Running:Yes
Slave_SQL_Running:Yes
//则表示没有问题