今天有时间写写,不然心坎里总有点不爽。单机多实例一直都是屌丝的处事风格。。。
实验环境
RHEL6.5
172.24.0.130 3306
172.24.0.130 3307
01、本次采用的MYSQL二进制快速安装
下载地址:
https://dev.mysql.com/downloads/mysql/
http://pan.baidu.com/s/1qYI0ybq
http://pan.baidu.com/s/1pLHM2TH 密码: pg5t
#截图操作
#根据需求选择对应的版本
02、解压并建立数据目录
tar zxf xxx.tar.gz -C /tmp
mkdir -p {data_3306,data3307} #存放数据
mkdir conf #放my.cnf
03、修改配置文件my.cnf
#3306my.cnf
[client] default-character-set=utf8 #客户端连接编码 [mysql] auto-rehash #客户端tab补全 default-character-set=utf8 #编码 [mysqld]
user=mysql #运行账户 port=3306 #定义端口 log-bin=mysql-bin #开启二进制日志 server-id=001 #定义服务ID max_allowed_packet=50M ###最大 wait_timeout=3600 ###等待超时默认s interactive_timeout=3600 ###活动超时 innodb_buffer_pool_size = 128M join_buffer_size = 128M sort_buffer_size = 2M read_rnd_buffer_size = 2M basedir=/tmp/mysql_mulit #MYSQL根目录 datadir=/tmp/mysql_mulit/data_3306 #MYSQL数据存放目录 socket=/tmp/3306_mysql.sock #套接字 init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 #定义数据库默认字符 server\collation 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-file=/tmp/mysql_mulit/data_3306/mysqld.pid #pid,多协议通信 tcp/sock
3307my.cnf
[client] default-character-set=utf8 #客户端连接编码 [mysql] auto-rehash #客户端tab补全 default-character-set=utf8 #编码 [mysqld]
user=mysql port=3307 #定义端口 log-bin=mysql-bin #开启二进制日志 server-id=011 #定义服务ID max_allowed_packet=50M ###最大 wait_timeout=3600 ###等待超时默认s interactive_timeout=3600 ###活动超时 innodb_buffer_pool_size = 128M join_buffer_size = 128M sort_buffer_size = 2M read_rnd_buffer_size = 2M basedir=/tmp/mysql_mulit #MYSQL根目录 datadir=/tmp/mysql_mulit/data_3307 #MYSQL数据存放目录 socket=/tmp/3307_mysql.sock #套接字 init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 #定义数据库默认字符 server\collation 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/3307_err.log #错误日志 pid-file=/tmp/mysql_mulit/data_3307/mysqld.pid #pid,多协议通信 tcp/sock
04、初始化数据库
./scripts/mysql_install_db --defaults-file=conf/3306my.cnf
./scripts/mysql_install_db --defaults-file=conf/3306my.cnf
05、启动数据库
./bin/mysqld_safe --defaults-file=conf/3306my.cnf &
./bin/mysqld_safe --defaults-file=conf/3307my.cnf &
06、初始化root密码
./bin/mysqladmin -P 3306 -u root password '123123'
./bin/mysqladmin -P 3307 -u root password '123123'
07、master主机设置(3306)
建立从复制账号
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, zabbix是主机名
查看Master信息
mysql> show master status; #目的跟slave对上口径
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000003 | 541 | | | |
+------------------+----------+--------------+------------------+-------------------+
08、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;
start slave; #启动从主机 stop slave;停止从主机
#截图中两个yes说明从机已经连接到主机