mysql5.6安装及实现双向备份

(一) 安装mysql5.6

安装包 : mysql-5.6.10 .tar.gz

安装步骤:

yum -y install cmake

tar -axvf  mysql-5.6.10 .tar.gz

cd mysql-5.6.10/

cmake .

make && make install

默认安装就行,会自动把数据库安装在/usr/local/mysql下

chown -R mysql.mysql /usr/local/mysql

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld

(由于之前习惯用mysqld这个命令,所以就把它也放在/etc/rc.d/init.d/ )

chkconfig --add mysqld

chkconfig mysqld on

service mysqld start (如果没报错,说明我们安装成功,如果有错误信息,可以先killall mysqld ,在重启mysqld下,如果还不行,就到google上找找)


(二)配置双向同步

说先配置my.cnf (我的系统是8G 内存,大家根据自己的电脑配置进行设置)

vi /etc/my.cnf

[mysqld]

log_bin = mylog.000001  (这个必须设置,我们根据log_bin文件进行同步)

basedir = /usr/local/mysql

datadir = /usr/local/mysql/data

skip-external-locking

key_buffer_size = 256M

max_allowed_packet = 1M

table_open_cache = 256

sort_buffer_size = 1M

read_buffer_size = 1M

#read_rnd_buffer_size = 4M

myisam_sort_buffer_size = 64M

thread_cache_size = 8

query_cache_size= 16M

thread_concurrency = 8

join_buffer_size = 32M

sort_buffer_size = 16M

read_rnd_buffer_size = 16M

join_buffer_size = 32M

sort_buffer_size = 16M

read_rnd_buffer_size = 16M

[mysqldump]

quick

max_allowed_packet = 66M


现在我们假设有两台服务器,ip地址分别是:A:192.168.1.2, B:192.168.1.3

创建数据库用户,使两个数据库可以互相访问

进入A

  1. mysql> grant replication slave on *.* to test@'192.168.1.3' identified by 'test';

  2. Query OK, 0 rows affected (0.01 sec)

  3. mysql> flush privileges;

  4. Query OK, 0 rows affected (0.00 sec)


进入B

  1. mysql> grant replication slave on *.* to test@'192.168.1.2' identified by 'test';

  2. Query OK, 0 rows affected (0.01 sec)

  3. mysql> flush privileges;

  4. Query OK, 0 rows affected (0.00 sec)


我们先做A主,B从,

进入A

  1. mysql> show master status;

  2. +--------------+----------+--------------+------------------+-------------------+

  3. | File         | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

  4. +--------------+----------+--------------+------------------+-------------------+

  5. | mylog.000001 |      412 |              |                  |                   |

  6. +--------------+----------+--------------+------------------+-------------------+

则:进入B进行配置

  1. mysql> CHANGE MASTER TO

  2.    -> MASTER_HOST='192.168.1.2',   (A的ip)

  3.    -> MASTER_USER='test',        

  4.    -> MASTER_PASSWORD='test',  

  5.    -> MASTER_LOG_FILE='mylog.000001',  

  6.    -> MASTER_LOG_POS=412;


mysql> start slave; 启动备份功能。

mysql> show slave status\G; 查看主从配置信息

  1.  Slave_IO_Running: Yes

  2.  Slave_SQL_Running: Yes

如果这两项都是 yes 的话,说明我们配置正确,


接下去,只要在A上重复在B上的操作,就可以实现主主备份了。

注意一点是,mysql5.6不支持在my.cnf 下配置主主备份。



你可能感兴趣的:(mysql5.6安装及实现双向备份)