- InnoDB 存儲引擎核心特性
5.1 種類
InnoDB
MyISAM
CSV
Memory
tokudb
myrocks
influxdb--->時序類數(shù)據(jù)庫,數(shù)據(jù)不能手工刪除,只能設置自動清理策略.
5.2 InnoDB 核心特性
事務
行鎖
熱備
MVCC
一致性hash
insert buffer
ACSR
聚簇索引
主從復制(GTID)
外鍵
5.3 事務 ACID
A: 原子性.事務的最小工作單元,不可以被拆分.不能產(chǎn)生中間狀態(tài),要么全成功,要么全失敗.
UNDO(回滾)+REDO(前滾)
C: 一致性. 在一個事務更新邏輯中,不管是處于事務更新前,中,結束.
本事務中操作的數(shù)據(jù)都終將保證一致狀態(tài),不會受到其他事務影響.
AID+鎖+MVCC等機制都是對數(shù)據(jù)的最終一致起到關鍵作用
I: 隔離性 . 隔離級別+鎖+MVCC
D: 持久性. 一旦被提交成功的數(shù)據(jù),不管宕機與否,都不會導致事務的更新丟失.
Redo
5.4 Redo 和 UNDO
5.5 MVCC 多版本并發(fā)控制
利用的是UnDO的快照.InnoDB引擎中,維護著多個版本的UnDO快照.
多事務并發(fā)環(huán)境中,互相不影響.只要多事務之間更新的數(shù)據(jù)鎖不互相沖突.事務是可以并發(fā)執(zhí)行的.
特性:
- 在RR級別下的,一致性快照讀是由MVCC保證的.在同一個事務生命周期內(nèi),獲取的一定是同一個版本數(shù)據(jù).
- 對于讀操作,實現(xiàn)的是非鎖定快照讀. 讀的操作不加鎖.
5.6 隔離級別
RC : 事務并發(fā)讀會更高一些. 防止臟讀. 會出現(xiàn) 不可重復讀和幻讀
RR : 可以防止臟讀和不可重復讀(一致性快照讀.),配合GAP和Next-lock實現(xiàn)防止幻讀
5.7 鎖機制
RL
GL
NL
MDL ----> DDL DCL
TL ----> DDL DCL
FTWRL ---> 全局鎖 ----> XBK備份非InnoDB
IS
S select xxx from xxx lock in shared mode;
IX
X select xxx from xxx for update;
5.8 碎片整理
alter table t1 engine=innodb
Pt-archiver
optimize table t1;
5.8 表空間遷移
create table t1
alter table t1 discard tablespace
alter table t1 import tablespace
5.9 自適應hash
加速索引讀取性能, 索引的索引
5.10 insert buffer
為了大量insert業(yè)務場景設計.
- 日志管理
6.1 log_error
錯誤 ----> [ERROR]
啟動
宕機
主從
鎖
工作狀態(tài)
6.2 binlog 二進制日志
如何截取二進制日志
show master status ; ----> 正在使用的二進制日志
show binlog events in 'xxxx' ----> 看事件
mysqlbinlog --start-position --stop-position xxxx.000009 > /backup/bin.sql
mysqlbinlog --include-gtids --exclude-gtids --skip-gtids > /backup/bin.sql
set sql_log_bin=0;
source
set sql_log_bin=1;
binlog_format :
SBR 語句模式
RBR 行模式
MBR 混合模式
滾動
flush logs
重啟
MySQLadmin flush-logs
達到1G
備份時會應用
binlog_server: mysqlbinlog
清理
expire_logs_days=15
參數(shù):
innodb_flush_log_at_trx_commit=1 ----> redo 刷寫策略
innodb_flush_method=O_direct
sync_binlog=1 ----> binlog 刷寫策略
6.3 slowlog
slow_query_log=1 # 慢日志開關
slow_query_log_file # 慢日志位置
long_query_time # 慢日志記錄條件(時間)
log_queries_not_using_indexes # 慢日志記錄條件(不走索引的)
mysqldumpslow
mysqlsla
pt-query-digest+Anemometer 圖形化展示慢日志
- 備份恢復
7.1 mysqldump
-A -B --master-data=2 --single-transaction --triggers -R -E --max_allowed_packet=64M
7.2 xbk
備份過程:
(1) ckpt,記錄LSN
(2) 備份innodb表
(3) 非InnoDB表,開啟FTWRL(Flush Tbales with read lock)全局讀鎖,拷貝文件,自動解鎖
(4) 并將備份過程中redo日志進行備份,記錄結束LSN
(5) 增量都是基于上次last_lsn,檢查所有變化的數(shù)據(jù)頁進行備份
備份策略:
1. full+inc+binlog
2. full+binlog
恢復過程:
單獨全備:
1. prepare 全備 : --apply-log
2. cp
全備+增量:
1. prepare 基礎全備 : --apply-log --redo-only
2. 增量到基礎全備,prepare增量: --apply-log --redo-only
3. 最后增量到基礎全備,prepare增量: --apply-log
4. prepare 終極全備 : --apply-log
5. 恢復全備
This option should be used when preparing the base full
backup and when merging all incrementals except the last one.
- 主從復制
8.1 主從復制搭建
傳統(tǒng)
gtid
8.2 主從復制原理
8.3 主從監(jiān)控
show slave status\G
8.4 主從故障分析
8.5 主從延時
8.6 演變
延時從:
SQL線程延時一段時間,回放日志.
怎么用? 解決邏輯損壞.
半同步概念 :
過濾復制配置:
MHA高可用
9.1 搭建
9.2 原理
9.3 故障處理高可用配合讀寫分離
分布式架構-MyCat
優(yōu)化
NoSQL
==========================================
MHA 故障環(huán)境修復:
- 修復主從
51/53節(jié)點:
mysql -S /tmp/mysql.sock -e "show slave status \G"|grep Running:
2.主庫修復vip
52節(jié)點:
[root@db02 ~]# ifconfig eth0:1 10.0.0.55/24
說明: 刪除vip?
ifconfig eth0:1 down
修復binlog_server
53節(jié)點:
[root@db03 ~]# cd /data/mysql/binlog/
[root@db03 /data/mysql/binlog]# rm -rf *
[root@db03 /data/mysql/binlog]# mysqlbinlog -R --host=10.0.0.52 --user=mha --password=mha --raw --stop-never mysql-bin.000001 &檢查配置文件
53節(jié)點:
[root@db03 /data/mysql/binlog]# vim /etc/mha/app1.cnf檢查SSH和主從
53節(jié)點:
masterha_check_ssh --conf=/etc/mha/app1.cnf
masterha_check_repl --conf=/etc/mha/app1.cnf啟動MHA
53節(jié)點:
nohup masterha_manager --conf=/etc/mha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/mha/app1/manager.log 2>&1 &
================================
讀寫分離
- 安裝
略.
2.配置
2.1 軟件路徑
[root@db03 ~]# cd /usr/local/mysql-proxy/
[root@db03 /usr/local/mysql-proxy]# ll
總用量 0
drwxr-xr-x 2 root root 75 11月 26 16:54 bin
drwxr-xr-x 2 root root 22 11月 26 16:54 conf
drwxr-xr-x 3 root root 331 11月 26 16:54 lib
drwxr-xr-x 2 root root 6 12月 17 2014 log
[root@db03 /usr/local/mysql-proxy]#
2.2 環(huán)境變量設置
[root@db03 /usr/local/mysql-proxy]# vim /etc/profile
export PATH=/usr/local/mysql-proxy/bin:$PATH
source /etc/profile
2.3 配置文件
[root@db03 /usr/local/mysql-proxy/conf]# cd /usr/local/mysql-proxy/conf
[root@db03 /usr/local/mysql-proxy/conf]# vim oldguo.cnf
[mysql-proxy]
admin-username = user
admin-password = pwd
proxy-backend-addresses = 10.0.0.55:3306
proxy-read-only-backend-addresses = 10.0.0.51:3306,10.0.0.53:3306
pwds = repl:3yb5jEku5h4=,mha:O2jBXONX098=
daemon = true
keepalive = true
event-threads = 8
log-level = message
log-path = /usr/local/mysql-proxy/log
sql-log=ON
proxy-address = 0.0.0.0:33060
admin-address = 0.0.0.0:2345
charset=utf8
2.4 啟動atlas
mysql-proxyd oldguo start
2.5 測試讀寫分離
讀:
[root@db03 ~]# mysql -umha -pmha -h10.0.0.53 -P33060
db03 [(none)]>select @@server_id;
寫:
db03 [(none)]>begin;
db03 [(none)]>select @@server_id;
db03 [(none)]>commit;
- Atlas 的管理(在線)
db03 [(none)]>select * from help;
+----------------------------+---------------------------------------------------------+
| command | description |
+----------------------------+---------------------------------------------------------+
| SELECT * FROM help | shows this help |
| SELECT * FROM backends | lists the backends and their state |
| SET OFFLINE backend_id is backend_ndx's id |
| SET ONLINE backend | example: "add master 127.0.0.1:3306", ... |
| ADD SLAVE backend_id | example: "remove backend 1", ... |
| SELECT * FROM clients | lists the clients |
| ADD CLIENT client | example: "remove client 192.168.1.2", ... |
| SELECT * FROM pwds | lists the pwds |
| ADD PWD pwd | example: "add enpwd user:encrypted_password", ... |
| REMOVE PWD $pwd | example: "remove pwd user", ... |
| SAVE CONFIG | save the backends to config file |
| SELECT VERSION | display the version of Atlas |
+----------------------------+---------------------------------------------------------+
16 rows in set (0.00 sec)
3.1 幫助查看
SELECT * FROM help
3.2 查看后端節(jié)點
db03 [(none)]>SELECT * FROM backends ;
+-------------+----------------+-------+------+
| backend_ndx | address | state | type |
+-------------+----------------+-------+------+
| 1 | 10.0.0.55:3306 | up | rw |
| 2 | 10.0.0.51:3306 | up | ro |
| 3 | 10.0.0.53:3306 | up | ro |
+-------------+----------------+-------+------+
3 rows in set (0.00 sec)
3.3 在線offline/online一個節(jié)點
db03 [(none)]>SET OFFLINE 3;
+-------------+----------------+---------+------+
| backend_ndx | address | state | type |
+-------------+----------------+---------+------+
| 3 | 10.0.0.53:3306 | offline | ro |
+-------------+----------------+---------+------+
1 row in set (0.00 sec)
db03 [(none)]>SELECT * FROM backends ;
+-------------+----------------+---------+------+
| backend_ndx | address | state | type |
+-------------+----------------+---------+------+
| 1 | 10.0.0.55:3306 | up | rw |
| 2 | 10.0.0.51:3306 | up | ro |
| 3 | 10.0.0.53:3306 | offline | ro |
+-------------+----------------+---------+------+
3 rows in set (0.00 sec)
db03 [(none)]>
db03 [(none)]>SET ONLINE 3;
+-------------+----------------+---------+------+
| backend_ndx | address | state | type |
+-------------+----------------+---------+------+
| 3 | 10.0.0.53:3306 | unknown | ro |
+-------------+----------------+---------+------+
1 row in set (0.00 sec)
3.4 添加/刪除節(jié)點
REMOVE BACKEND 2;
REMOVE BACKEND 1;
ADD SLAVE 10.0.0.51:3306
ADD master 10.0.0.55:3306
3.5 開用戶
3.5.1. MySQL主庫建用戶,授權
db02 [(none)]>grant all on . to root@'localhost' identified by '123';
3.5.2. Atlas 添加用戶
ADD PWD root:123
3.6 永久保存配置到文件
db03 [(none)]>save config;
- MyCAT基礎架構準備
2.1 環(huán)境準備:
兩臺虛擬機 db01 db02
每臺創(chuàng)建四個mysql實例:3307 3308 3309 3310
2.2 刪除歷史環(huán)境:
pkill mysqld
rm -rf /data/330*
mv /etc/my.cnf /etc/my.cnf.bak
2.3 創(chuàng)建相關目錄初始化數(shù)據(jù)
mkdir /data/33{07..10}/data -p
mysqld --initialize-insecure --user=mysql --datadir=/data/3307/data --basedir=/usr/local/mysql
mysqld --initialize-insecure --user=mysql --datadir=/data/3308/data --basedir=/usr/local/mysql
mysqld --initialize-insecure --user=mysql --datadir=/data/3309/data --basedir=/usr/local/mysql
mysqld --initialize-insecure --user=mysql --datadir=/data/3310/data --basedir=/usr/local/mysql
2.4 準備配置文件和啟動腳本
========db01==============
cat >/data/3307/my.cnf<<EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/data/3307/data
socket=/data/3307/mysql.sock
port=3307
log-error=/data/3307/mysql.log
log_bin=/data/3307/mysql-bin
binlog_format=row
skip-name-resolve
server-id=7
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
EOF
cat >/data/3308/my.cnf<<EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/data/3308/data
port=3308
socket=/data/3308/mysql.sock
log-error=/data/3308/mysql.log
log_bin=/data/3308/mysql-bin
binlog_format=row
skip-name-resolve
server-id=8
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
EOF
cat >/data/3309/my.cnf<<EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/data/3309/data
socket=/data/3309/mysql.sock
port=3309
log-error=/data/3309/mysql.log
log_bin=/data/3309/mysql-bin
binlog_format=row
skip-name-resolve
server-id=9
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
EOF
cat >/data/3310/my.cnf<<EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/data/3310/data
socket=/data/3310/mysql.sock
port=3310
log-error=/data/3310/mysql.log
log_bin=/data/3310/mysql-bin
binlog_format=row
skip-name-resolve
server-id=10
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
EOF
cat >/etc/systemd/system/mysqld3307.service<<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/data/3307/my.cnf
LimitNOFILE = 5000
EOF
cat >/etc/systemd/system/mysqld3308.service<<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/data/3308/my.cnf
LimitNOFILE = 5000
EOF
cat >/etc/systemd/system/mysqld3309.service<<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/data/3309/my.cnf
LimitNOFILE = 5000
EOF
cat >/etc/systemd/system/mysqld3310.service<<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/data/3310/my.cnf
LimitNOFILE = 5000
EOF
========db02===============
cat >/data/3307/my.cnf<<EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/data/3307/data
socket=/data/3307/mysql.sock
port=3307
log-error=/data/3307/mysql.log
log_bin=/data/3307/mysql-bin
binlog_format=row
skip-name-resolve
server-id=17
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
EOF
cat >/data/3308/my.cnf<<EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/data/3308/data
port=3308
socket=/data/3308/mysql.sock
log-error=/data/3308/mysql.log
log_bin=/data/3308/mysql-bin
binlog_format=row
skip-name-resolve
server-id=18
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
EOF
cat >/data/3309/my.cnf<<EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/data/3309/data
socket=/data/3309/mysql.sock
port=3309
log-error=/data/3309/mysql.log
log_bin=/data/3309/mysql-bin
binlog_format=row
skip-name-resolve
server-id=19
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
EOF
cat >/data/3310/my.cnf<<EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/data/3310/data
socket=/data/3310/mysql.sock
port=3310
log-error=/data/3310/mysql.log
log_bin=/data/3310/mysql-bin
binlog_format=row
skip-name-resolve
server-id=20
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
EOF
cat >/etc/systemd/system/mysqld3307.service<<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/data/3307/my.cnf
LimitNOFILE = 5000
EOF
cat >/etc/systemd/system/mysqld3308.service<<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/data/3308/my.cnf
LimitNOFILE = 5000
EOF
cat >/etc/systemd/system/mysqld3309.service<<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/data/3309/my.cnf
LimitNOFILE = 5000
EOF
cat >/etc/systemd/system/mysqld3310.service<<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/data/3310/my.cnf
LimitNOFILE = 5000
EOF
2.5 修改權限弥锄,啟動多實例
chown -R mysql.mysql /data/*
systemctl start mysqld3307
systemctl start mysqld3308
systemctl start mysqld3309
systemctl start mysqld3310
mysql -S /data/3307/mysql.sock -e "show variables like 'server_id'"
mysql -S /data/3308/mysql.sock -e "show variables like 'server_id'"
mysql -S /data/3309/mysql.sock -e "show variables like 'server_id'"
mysql -S /data/3310/mysql.sock -e "show variables like 'server_id'"
2.6 節(jié)點主從規(guī)劃
箭頭指向誰是主庫
10.0.0.51:3307 <-----> 10.0.0.52:3307
10.0.0.51:3309 ------> 10.0.0.51:3307
10.0.0.52:3309 ------> 10.0.0.52:3307
10.0.0.52:3308 <-----> 10.0.0.51:3308
10.0.0.52:3310 -----> 10.0.0.52:3308
10.0.0.51:3310 -----> 10.0.0.51:3308
2.7 分片規(guī)劃
shard1:
Master:10.0.0.51:3307
slave1:10.0.0.51:3309
Standby Master:10.0.0.52:3307
slave2:10.0.0.52:3309
shard2:
Master:10.0.0.52:3308
slave1:10.0.0.52:3310
Standby Master:10.0.0.51:3308
slave2:10.0.0.51:3310
2.8 開始配置
shard1
10.0.0.51:3307 <-----> 10.0.0.52:3307
db02
mysql -S /data/3307/mysql.sock -e "grant replication slave on . to repl@'10.0.0.%' identified by '123';"
mysql -S /data/3307/mysql.sock -e "grant all on . to root@'10.0.0.%' identified by '123' with grant option;"
db01
mysql -S /data/3307/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.52', MASTER_PORT=3307, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"
mysql -S /data/3307/mysql.sock -e "start slave;"
mysql -S /data/3307/mysql.sock -e "show slave status\G"
db02
mysql -S /data/3307/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.51', MASTER_PORT=3307, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"
mysql -S /data/3307/mysql.sock -e "start slave;"
mysql -S /data/3307/mysql.sock -e "show slave status\G"
10.0.0.51:3309 ------> 10.0.0.51:3307
db01
mysql -S /data/3309/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.51', MASTER_PORT=3307, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"
mysql -S /data/3309/mysql.sock -e "start slave;"
mysql -S /data/3309/mysql.sock -e "show slave status\G"
10.0.0.52:3309 ------> 10.0.0.52:3307
db02
mysql -S /data/3309/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.52', MASTER_PORT=3307, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"
mysql -S /data/3309/mysql.sock -e "start slave;"
mysql -S /data/3309/mysql.sock -e "show slave status\G"
shard2
10.0.0.52:3308 <-----> 10.0.0.51:3308
db01
mysql -S /data/3308/mysql.sock -e "grant replication slave on . to repl@'10.0.0.%' identified by '123';"
mysql -S /data/3308/mysql.sock -e "grant all on . to root@'10.0.0.%' identified by '123' with grant option;"
db02
mysql -S /data/3308/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.51', MASTER_PORT=3308, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"
mysql -S /data/3308/mysql.sock -e "start slave;"
mysql -S /data/3308/mysql.sock -e "show slave status\G"
db01
mysql -S /data/3308/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.52', MASTER_PORT=3308, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"
mysql -S /data/3308/mysql.sock -e "start slave;"
mysql -S /data/3308/mysql.sock -e "show slave status\G"
10.0.0.52:3310 -----> 10.0.0.52:3308
db02
mysql -S /data/3310/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.52', MASTER_PORT=3308, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"
mysql -S /data/3310/mysql.sock -e "start slave;"
mysql -S /data/3310/mysql.sock -e "show slave status\G"
10.0.0.51:3310 -----> 10.0.0.51:3308
db01
mysql -S /data/3310/mysql.sock -e "CHANGE MASTER TO MASTER_HOST='10.0.0.51', MASTER_PORT=3308, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='123';"
mysql -S /data/3310/mysql.sock -e "start slave;"
mysql -S /data/3310/mysql.sock -e "show slave status\G"
2.9 檢測主從狀態(tài)
mysql -S /data/3307/mysql.sock -e "show slave status\G"|grep Yes
mysql -S /data/3308/mysql.sock -e "show slave status\G"|grep Yes
mysql -S /data/3309/mysql.sock -e "show slave status\G"|grep Yes
mysql -S /data/3310/mysql.sock -e "show slave status\G"|grep Yes
注:如果中間出現(xiàn)錯誤,在每個節(jié)點進行執(zhí)行以下命令
mysql -S /data/3307/mysql.sock -e "stop slave; reset slave all;"
mysql -S /data/3308/mysql.sock -e "stop slave; reset slave all;"
mysql -S /data/3309/mysql.sock -e "stop slave; reset slave all;"
mysql -S /data/3310/mysql.sock -e "stop slave; reset slave all;"