mysql主从复制


安装配置环境:
	os:centos 5.4
	mysql:5.5.37
	虚拟server1:mysql_master(192.168.40.241)
	虚拟server2:mysql_slave(192.168.40.242)

安装Mysql:
    可参考解压后的INSTALL-BINARY,如下:

	shell> groupadd mysql
	shell> useradd -r -g mysql mysql
	shell> cd /usr/local
	shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
	shell> ln -s full-path-to-mysql-VERSION-OS mysql
	shell> cd mysql
	shell> chown -R mysql .
	shell> chgrp -R mysql .
	shell> scripts/mysql_install_db --user=mysql
	shell> chown -R root .
	shell> chown -R mysql data
	# Next command is optional
	shell> cp support-files/my-medium.cnf /etc/my.cnf
	shell> bin/mysqld_safe --user=mysql &
	# Next command is optional
	shell> cp support-files/mysql.server /etc/init.d/mysql.server

配置mysql_master的Mysql权限:
	grant all on *.* to user@192.168.40.242 identified by '123';

配置mysql_slave的/etc/my.cnf: 1、修改server-id=2(mysql_master默认为1,何证server-id的唯一性即可) 2、重启mysql服务 3、登录mysql命令行中执行change master to master_host='192.168.40.241',master_user='user',master_password='123' 4、slave start (启动复制线程) 常用的相关命令: slave start; --启动复制线程 slave stop; --停止复制线程 reset slave; --重置复制线程 show slave status; --显示复制线程的状态 show slave statusG; --显示复制线程的状态(分行显示) show master statusG; --显示主数据库的状态(分行显示) show master logs --显示主数据库日志,需在主数据库上运行 change master to; --动态改变到主数据库的配置 show processlist --显示有哪些线程在运行
原文地址:https://www.cnblogs.com/zengxianxi/p/3705356.html