mysql5.6主从同部署
MySQL 是一个特性丰富、性能高效、可靠性强、易用性高、成本低廉的数据库解决方案,适用于各种应用程序,从小规模的个人网站到大型的企业应用
env
- centos6.5
- mysql5.6(master/slave)
1.downlaod mysql
- https://dev.mysql.com/downloads/mysql/
- http://pan.baidu.com/s/1qYI0ybq
- http://pan.baidu.com/s/1pLHM2TH 密码: pg5t
2.解压
tar zxf xxx.tar.gz -C /tmp
mkdir -p {data_3306,data3307} //存放数据
mkdir conf //放my.cnf
3.修改配置my.cnf
[client]
#客户端连接编码
default-character-set=utf8
[mysql]
#客户端tab补全
auto-rehash
#编码
default-character-set=utf8
[mysqld]
#运行账户
user=mysql
#定义端口
port=3306
#开启二进制日志
log-bin=mysql-bin
#定义服务ID
server-id=001
#导出导入限制
max_allowed_packet=50M
#等待超时默认s
wait_timeout=3600
#活动超时
interactive_timeout=3600
#pool_size
innodb_buffer_pool_size = 512M
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
#MYSQL根目录
basedir=/tmp/mysql_mulit
#MYSQL数据存放目录
datadir=/tmp/mysql_mulit/data_3306
#套接字
socket=/tmp/3306_mysql.sock
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
#定义数据库默认字符 server\collation
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#对表的大小写不敏感
lower_case_table_names = 0
[mysqld_safe]
#错误日志
log-error=/tmp/3306_err.log
#pid,多协议通信 tcp/sock
pid-file=/tmp/mysql_mulit/data_3306/mysqld.pid
4.init db
./scripts/mysql_install_db --defaults-file=conf/3306my.cnf
./scripts/mysql_install_db --defaults-file=conf/3307my.cnf
5.startdb
./bin/mysqld_safe --defaults-file=conf/3306my.cnf &
./bin/mysqld_safe --defaults-file=conf/3307my.cnf &
6.reset root
./bin/mysqladmin -P 3306 -u root password '123123'
./bin/mysqladmin -P 3307 -u root password '123123'
7.master(3306)
7.1建立从复制账号
grant replication slave on *.* to 'mysync'@'%' identified by '123456'; #所有IP
grant replication slave on *.* to 'mysync'@'localhost' identified by '123456'; #127.0.0.1
grant replication slave on *.* to 'mysync'@'zabibx' identified by '123456'; #172.24.0.130,
7.2查看Master信息
mysql> show master status; #目的跟slave对上口径
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 | 541 | | | |
+------------------+----------+--------------+------------------+-------------------+
8.slave(3307)
进入mysql与master主机建立连接
change master to master_host='172.24.0.130',master_port=3306,master_user='mysync',master_password='123456', master_log_file='mysql-bin.000003',master_log_pos=541;
show slave status\G;
slave_io_running yes
slave_sql_running yes
#启动从主机
start slave;
#停止从主机
stop slave;