Mysql多实例安装+主从复制+读写分离 -学习笔记
<h1>
<span class="link_title"><a href="/wmj2004/article/details/53393528">
Mysql多实例安装+主从复制+读写分离 -学习笔记
</a>
</span>
</h1>
<style type="text/css">
.embody{
padding:10px 10px 10px;
margin:0 -20px;
border-bottom:solid 1px #ededed;
}
.embody_b{
margin:0 ;
padding:10px 0;
}
.embody .embody_t,.embody .embody_c{
display: inline-block;
margin-right:10px;
}
.embody_t{
font-size: 12px;
color:#999;
}
.embody_c{
font-size: 12px;
}
.embody_c img,.embody_c em{
display: inline-block;
vertical-align: middle;
}
.embody_c img{
width:30px;
height:30px;
}
.embody_c em{
margin: 0 20px 0 10px;
color:#333;
font-style: normal;
}
</style>
<script type="text/javascript">
$(function () {
try
{
var lib = eval("("+$("#lib").attr("value")+")");
var html = "";
if (lib.err == 0) {
$.each(lib.data, function (i) {
var obj = lib.data[i];
//html += '<img src="' + obj.logo + '"/>' + obj.name + " ";
html += ' <a href="' + obj.url + '" target="_blank">';
html += ' <img src="' + obj.logo + '">';
html += ' <em><b>' + obj.name + '</b></em>';
html += ' </a>';
});
if (html != "") {
setTimeout(function () {
$("#lib").html(html);
$("#embody").show();
}, 100);
}
}
} catch (err)
{ }
});
</script>
一. Mysql多实例编译安装
-------------------------------------
1.多实例定义:
同一套mysql程序,不同的“my.cnf,启动程序,端口”。属于逻辑上面的多实例。
2.下载mysql-5.5.32.tar.gz
3.安装相关依赖:
yum install ncurses-devel libaio-devel cmake gcc-c++
4.创建用户:
useradd mysql -s /sbin/nologin -M
5.解压缩开始编译:
- cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.32/ -DMYSQL_DATADIR=/data/mysql \
- -DMYSQL_UNIX_ADDR=/usr/local/mysql-5.5.32/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci \
- -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 \
- -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
- -DWITHOUT_PARTITION_STORAGE_ENGINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 \
- -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.5.32/ -DMYSQL_DATADIR=/data/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.5.32/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0
make&&make install
6.创建实例目录:
mkdir -p /data/{3306,3307}/data
7.创建配置文件:
PS:server-id 每个实例要不一样。
vim /data/3306/my.cnf
- [client]
- port = 3306
- socket = /data/3306/mysql.sock
- [mysql]
- no-auto-rehash
- [mysqld]
- user = mysql
- port = 3306
- socket = /data/3306/mysql.sock
- basedir = /usr/local/mysql-5.5.32
- datadir = /data/3306/data
- open_files_limit = 1024
- character-set-server = utf8
- back_log = 600
- max_connections = 800
- max_connect_errors = 3000
- table_cache = 614
- external-locking = FALSE
- max_allowed_packet =8M
- sort_buffer_size = 1M
- join_buffer_size = 1M
- thread_cache_size = 100
- thread_concurrency = 2
- query_cache_size = 2M
- query_cache_limit = 1M
- query_cache_min_res_unit = 2k
- #default_table_type = InnoDB
- thread_stack = 192K
- #transaction_isolation = READ-COMMITTED
- tmp_table_size = 2M
- max_heap_table_size = 2M
- long_query_time = 1
- #log_long_format
- #log-error = /data/3306/error.log
- #log-slow-queries = /data/3306/slow.log
- pid-file = /data/3306/mysql.pid
- log-bin = /data/3306/mysql-bin
- relay-log = /data/3306/relay-bin
- relay-log-info-file = /data/3306/relay-log.info
- binlog_cache_size = 1M
- max_binlog_cache_size = 1M
- max_binlog_size = 2M
- expire_logs_days = 7
- key_buffer_size = 16M
- read_buffer_size = 1M
- read_rnd_buffer_size = 1M
- bulk_insert_buffer_size = 1M
- #myisam_sort_buffer_size = 1M
- #myisam_max_sort_file_size = 10G
- #myisam_max_extra_sort_file_size = 10G
- #myisam_repair_threads = 1
- #myisam_recover
- lower_case_table_names = 1
- skip-name-resolve
- slave-skip-errors = 1032,1062
- #replicate-ignore-db = mysql
- server-id = 1
- innodb_additional_mem_pool_size = 4M
- innodb_buffer_pool_size = 16G #设置成内存的一半最好
- innodb_data_file_path = ibdata1:128M:autoextend
- innodb_file_io_threads = 4
- innodb_thread_concurrency = 8
- innodb_flush_log_at_trx_commit = 2
- innodb_log_buffer_size = 2M
- innodb_log_file_size = 4M
- innodb_log_files_in_group = 3
- innodb_max_dirty_pages_pct = 90
- innodb_lock_wait_timeout = 120
- innodb_file_per_table = 0
- [mysqldump]
- quick
- max_allowed_packet = 2M
- [mysqld_safe]
- log-error=/data/3306/mysql_3306.err
- pid-file=/data/3306/mysqld.pid
[client]
port = 3306
socket = /data/3306/mysql.sock [mysql]
no-auto-rehash [mysqld]
user = mysql
port = 3306
socket = /data/3306/mysql.sock
basedir = /usr/local/mysql-5.5.32
datadir = /data/3306/data
open_files_limit = 1024
character-set-server = utf8
back_log = 600
max_connections = 800
max_connect_errors = 3000
table_cache = 614
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 100
thread_concurrency = 2
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2kdefault_table_type = InnoDB
thread_stack = 192Ktransaction_isolation = READ-COMMITTED
tmp_table_size = 2M
max_heap_table_size = 2M
long_query_time = 1log_long_format
log-error = /data/3306/error.log
log-slow-queries = /data/3306/slow.log
pid-file = /data/3306/mysql.pid
log-bin = /data/3306/mysql-bin
relay-log = /data/3306/relay-bin
relay-log-info-file = /data/3306/relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
expire_logs_days = 7
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1Mmyisam_sort_buffer_size = 1M
myisam_max_sort_file_size = 10G
myisam_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062replicate-ignore-db = mysql
server-id = 1 innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 16G #设置成内存的一半最好
innodb_data_file_path = ibdata1:128M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 2M [mysqld_safe]
log-error=/data/3306/mysql_3306.err
pid-file=/data/3306/mysqld.pid
vim /data/3307/my.cnf
- [client]
- port = 3307
- socket = /data/3307/mysql.sock
- [mysql]
- no-auto-rehash
- [mysqld]
- user = mysql
- port = 3307
- socket = /data/3307/mysql.sock
- basedir = /usr/local/mysql-5.5.32
- datadir = /data/3307/data
- open_files_limit = 1024
- character-set-server = utf8
- back_log = 600
- max_connections = 800
- max_connect_errors = 3000
- table_cache = 614
- external-locking = FALSE
- max_allowed_packet =8M
- sort_buffer_size = 1M
- join_buffer_size = 1M
- thread_cache_size = 100
- thread_concurrency = 2
- query_cache_size = 2M
- query_cache_limit = 1M
- query_cache_min_res_unit = 2k
- #default_table_type = InnoDB
- thread_stack = 192K
- #transaction_isolation = READ-COMMITTED
- tmp_table_size = 2M
- max_heap_table_size = 2M
- #long_query_time = 1
- #log_long_format
- #log-error = /data/3307/error.log
- #log-slow-queries = /data/3307/slow.log
- pid-file = /data/3307/mysql.pid
- #log-bin = /data/3307/mysql-bin
- relay-log = /data/3307/relay-bin
- relay-log-info-file = /data/3307/relay-log.info
- binlog_cache_size = 1M
- max_binlog_cache_size = 1M
- max_binlog_size = 2M
- expire_logs_days = 7
- key_buffer_size = 16M
- read_buffer_size = 1M
- read_rnd_buffer_size = 1M
- bulk_insert_buffer_size = 1M
- #myisam_sort_buffer_size = 1M
- #myisam_max_sort_file_size = 10G
- #myisam_max_extra_sort_file_size = 10G
- #myisam_repair_threads = 1
- #myisam_recover
- lower_case_table_names = 1
- skip-name-resolve
- slave-skip-errors = 1032,1062
- #replicate-ignore-db = mysql
- server-id = 3
- innodb_additional_mem_pool_size = 4M
- innodb_buffer_pool_size = 16G #设置成内存的一半
- innodb_data_file_path = ibdata1:128M:autoextend
- innodb_file_io_threads = 4
- innodb_thread_concurrency = 8
- innodb_flush_log_at_trx_commit = 2
- innodb_log_buffer_size = 2M
- innodb_log_file_size = 4M
- innodb_log_files_in_group = 3
- innodb_max_dirty_pages_pct = 90
- innodb_lock_wait_timeout = 120
- innodb_file_per_table = 0
- [mysqldump]
- quick
- max_allowed_packet = 2M
- [mysqld_safe]
- log-error=/data/3307/mysql_3307.err
- pid-file=/data/3307/mysqld.pid
[client]
port = 3307
socket = /data/3307/mysql.sock [mysql]
no-auto-rehash [mysqld]
user = mysql
port = 3307
socket = /data/3307/mysql.sock
basedir = /usr/local/mysql-5.5.32
datadir = /data/3307/data
open_files_limit = 1024
character-set-server = utf8
back_log = 600
max_connections = 800
max_connect_errors = 3000
table_cache = 614
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 100
thread_concurrency = 2
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2kdefault_table_type = InnoDB
thread_stack = 192Ktransaction_isolation = READ-COMMITTED
tmp_table_size = 2M
max_heap_table_size = 2Mlong_query_time = 1
log_long_format
log-error = /data/3307/error.log
log-slow-queries = /data/3307/slow.log
pid-file = /data/3307/mysql.pidlog-bin = /data/3307/mysql-bin
relay-log = /data/3307/relay-bin
relay-log-info-file = /data/3307/relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
expire_logs_days = 7
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1Mmyisam_sort_buffer_size = 1M
myisam_max_sort_file_size = 10G
myisam_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062replicate-ignore-db = mysql
server-id = 3 innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 16G #设置成内存的一半
innodb_data_file_path = ibdata1:128M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 2M [mysqld_safe]
log-error=/data/3307/mysql_3307.err
pid-file=/data/3307/mysqld.pid
8.创建启动脚本:
vim /data/3306/mysql
#3307只要改动port参数就可以
- #!/bin/sh
- #init
- port=3306
- mysql_user="root"
- mysql_pwd="Root123"
- cmdpath="/usr/local/mysql-5.5.32/bin"
- mysql_sock="/data/${port}/mysql.sock"
- #startup function
- function_start_mysql()
- {
- if [ ! -e "$mysql_sock" ];then
- echo "starting mysql…"
- /bin/sh ${cmdpath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /devull &
- else
- echo "mysql is running…"
- exit
- fi
- }
- #stop function
- function_stop_mysql()
- {
- if [ ! -e "$mysql_sock" ];then
- echo "mysql is stopped…"
- exit
- else
- echo "stoping mysql…"
- ${cmdpath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown
- fi
- }
- #restart function
- function_restart_mysql()
- {
- echo "restarting mysql…"
- function_stop_mysql
- sleep 2
- function_start_mysql
- }
- case $1 in
- start)
- function_start_mysql
- ;;
- stop)
- function_stop_mysql
- ;;
- restart)
- function_restart_mysql
- ;;
- *)
- echo "usage: /data/${port}/mysql {start|stop|restart}"
- esac
#!/bin/shinit
port=3306
mysql_user="root"
mysql_pwd="Root123"
cmdpath="/usr/local/mysql-5.5.32/bin"
mysql_sock="/data/${port}/mysql.sock"startup function
function_start_mysql()
{
if [ ! -e "$mysql_sock" ];then
echo "starting mysql…" /bin/sh ${cmdpath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /devull &
else
echo "mysql is running…"
exit
fi
}stop function
function_stop_mysql()
{
if [ ! -e "$mysql_sock" ];then
echo "mysql is stopped…"
exit
else
echo "stoping mysql…"
${cmdpath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown
fi }restart function
function_restart_mysql()
{
echo "restarting mysql…"
function_stop_mysql
sleep 2
function_start_mysql
} case $1 in start) function_start_mysql
;; stop) function_stop_mysql
;; restart) function_restart_mysql
;; *)
echo "usage: /data/${port}/mysql {start|stop|restart}"
esac
9.修改目录权限:
chown -R mysql:mysql /data/
find /data -type f -name mysql -exec chmod 700 {} \;
10.添加环境变量:
echo 'export PATH=/usr/local/mysql-5.5.32/bin/:$PATH' >> /etc/profile
11.初始化数据库:
cd /usr/local/mysql-5.5.32/scripts/
./mysql_install_db --basedir=/usr/local/mysql-5.5.32/ --datadir=/data/3306/data/ --user=mysql
./mysql_install_db --basedir=/usr/local/mysql-5.5.32/ --datadir=/data/3307/data/ --user=mysql
12.启动数据库:
/data/3306/mysql start
/data/3307/mysql start
13.设置数据库root密码:
mysqladmin -uroot password Root123 -S /data/3306/mysql.sock
mysqladmin -uroot password Root456 -S /data/3307/mysql.sock
14.登陆数据库:
mysql -uroot -pRoot123 -S /data/3306/mysql.sock
mysql -uroot -pRoot456 -S /data/3307/mysql.sock
15.远程登陆数据库:
mysql -uroot -pRoot123 -h 172.16.1.214 -P 3306
二. Mysql主从复制基础
-------------------------------------
1.主动复制架构图:
2.主从复制流程图:
3.主从复制条件:
#我们下面的操作是多实例主从复制,3306为主库,3307为从库。
主库要开启log-bin,主库和从库的server-id要不一样。
4.在主库上面创建同步用户:
mysql> grant replication slave on *.* to 'rep'@'172.16.1.%' identified by 'Root1234'; #后面的密码要设置复杂些。
mysql> flush privileges;
5.导出主库数据文件:
- 一。常规方法:
- mysql> flush table with read lock; #先锁表,锁表后不能退出mysql窗口,否则失效
- mysql> show master status; #记录bin-log的位置信息
- +------------------+----------+--------------+------------------+
- | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
- +------------------+----------+--------------+------------------+
- | mysql-bin.000004 | 560 | | |
- +------------------+----------+--------------+------------------+
- mysqldump -uroot -pRoot123 -S /data/3306/mysql.sock --events -A -B|gzip >/tmp/bak_$(date +%F).sql.gz
- mysql> unlock tables; #解锁数据库
- 二。快捷方法:
- mysqldump -uroot -pRoot123 -S /data/3306/mysql.sock --events -A -B -F --master-data=2 -x|gzip >/tmp/bak_f_$(date +%F).sql.gz
- -x 自动锁表
- -F --master-data=2 以备注形式记录bin-log的位置。(可以打开文件看头部备注信息)
一。常规方法:
mysql> flush table with read lock; #先锁表,锁表后不能退出mysql窗口,否则失效
mysql> show master status; #记录bin-log的位置信息
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000004 | 560 | | |
+------------------+----------+--------------+------------------+
mysqldump -uroot -pRoot123 -S /data/3306/mysql.sock --events -A -B|gzip >/tmp/bak_$(date +%F).sql.gz
mysql> unlock tables; #解锁数据库 二。快捷方法:
mysqldump -uroot -pRoot123 -S /data/3306/mysql.sock --events -A -B -F --master-data=2 -x|gzip >/tmp/bak_f_$(date +%F).sql.gz
-x 自动锁表
-F --master-data=2 以备注形式记录bin-log的位置。(可以打开文件看头部备注信息)
6.还原备份内容到从库:
gzip -d bak_2016-12-02.sql.gz
mysql -uroot -pRoot456 -S /data/3307/mysql.sock < bak_2016-12-02.sql
7.在从库创建master_info文件,并启动同步:
- mysql -uroot -pRoot456 -S /data/3307/mysql.sock <<EOF
- CHANGE MASTER TO
- MASTER_HOST='172.16.1.214',
- MASTER_PORT=3306,
- MASTER_USER='rep',
- MASTER_PASSWORD='Root1234',
- MASTER_LOG_FILE='mysql-bin.000004',
- MASTER_LOG_POS=560;
- EOF
- mysql> start slave; #开启同步
- mysql> show slave status \G ; #查看同步状态信息
mysql -uroot -pRoot456 -S /data/3307/mysql.sock <<EOF
CHANGE MASTER TO
MASTER_HOST='172.16.1.214',
MASTER_PORT=3306,
MASTER_USER='rep',
MASTER_PASSWORD='Root1234',
MASTER_LOG_FILE='mysql-bin.000004',
MASTER_LOG_POS=560;
EOF mysql> start slave; #开启同步
mysql> show slave status \G ; #查看同步状态信息
8.监控mysql主从复制的状态指标:
mysql -uroot -pRoot456 -S /data/3307/mysql.sock -e "show slave status \G ;" | egrep -i "_Running|_Behind"
Slave_IO_Running: Yes #同步进程是否启动
Slave_SQL_Running: Yes #sql进程是否启动
Seconds_Behind_Master: 0 #从库同步完成需要的时间
三. Mysql主主复制+读写分离进阶
--------------------------------------------------------------------
1.如果出现同步错误,需要忽略错误,进行下条语句继续同步。
- mysql> stop slave;
- mysql> set global sql_slave_skip_counter =1;
- mysql> start slave
mysql> stop slave;
mysql> set global sql_slave_skip_counter =1;
mysql> start slave
2.通过配置文件自动忽略同步错误“1007”,生产环境主从分离要用:
vim /data/3307/my.cnf
slave-skip-errors = 1032,1062,1007,1008
3.让从库开启bin_log的办法:
vim /data/3307/my.cnf
- log-slave-updates
- log-bin = /data/3307/mysql-bin
- expire_logs_days = 7 #日志只保留7天
log-slave-updates
log-bin = /data/3307/mysql-bin
expire_logs_days = 7 #日志只保留7天
4,.双主库同步方案:
a.让表的ID自增,让主1写1,3,5 主2 写2,4,6。
- A增加:
- auto_increment_increment = 2
- auto_increment_offset=1
- B增加:
- <p> b.不让表的ID自增,通过WEB程序去seq服务器取ID,写入双主。</p>
A增加:
auto_increment_increment = 2
auto_increment_offset=1
B增加: b.不让表的ID自增,通过WEB程序去seq服务器取ID,写入双主。
5.读写分离的方案:
a.通过开发的程序控制读写的位置。 (推荐)
b.通过开源软件实现。(Amoeba,Mysql_proxy)
c.自己开发DAL层。(大公司用)
6.增量备份步骤:
一。选择一台从库,不对外提供业务,专门用了做备份。此从库开启bin_log功能,做增量备份。
二。备份的时候需要停止sql线程,在用mysqldump备份:
stop slave sql_thread; #停止sql线程,不会停止同步IO进程
三。然后将备份文件和bin_log文件远程保存起来。
下面命令可以用来远程备份bin_log:
mysqlbinlog --read-from-remote-server --raw --host=172.16.1.214 --port=3306 --user=rep --password=Root1234 --stop-never mysql-bin.000001
7.主从复制延时原因:
a.从库太多,一般要3-5个
b.从库配置太低。
c.慢sql过多。
d.高版本mysql支持多线程复制
8.同一账号在主从库拥有不同权限方案:
a.在主库上创建拥有读写权限账号,然后再从库上面收回写入权限。
mysql> grant insert,update,delete,select on *.* to web@'172.16.1.%' identified by '123'; #创建web用户对所有表拥有读写权限,主库执行。
mysql> show grants form web@'172.16.1.%'; #查看用户权限
mysql> REVOKE insert,update,delete ON *.* FROM 'web'@'172.16.1.%'; #回收web用户写入权限,从库执行
b.从库不同步mysql授权表:(推荐方案)
my.cnf 里面加:
replicate-ignore-db = mysql
binlog-ignore-db = mysql
c.在从库设置read-only:
mysql> set global read_only=1;
或者 my.cnf 加 read-only
四. Mysql 灾难恢复演练
--------------------------------------------------------------------
1.主库当机从库接管方案:
a.半同步从库(谷歌半同步插件)。
b.选一台从库什么都不干,等着接管。
c.当机后选举一台从库来当主库。
2.查看从库的同步状态:
mysql> show processlist\G;
3.手动从库提升成主库的步骤:
a.停止同步,重置master。
mysql> stop slave ;
mysql> reset master;
b.删除目录文件里面的master.info 和 relay-bin。
c.取消read-only设置,确认bin-log是否开启。
d.重启数据库。
PS: 有一个软件“MHA”可以自动实现上面操作。
4.mysql的高可用方案:
MYSQL+HA+DRBD
MYSQL+MHA
Mysql多实例安装+主从复制+读写分离 -学习笔记的更多相关文章
- Windows下MySQL多实例安装/主从复制/重置密码
Windows创建MySQL多实例 安装MYSQL和实例1 运行mysql-installer-community-5.7.16.0.msi 选择组件 MySQL Server 5.7.16 – X6 ...
- mysql主从复制-读写分离
mysql主从复制+读写分离 环境:mysql主:193.168.1.1mysql从:193.168.1.2amoeba代理:193.168.1.3########################## ...
- MySQL 主从复制&读写分离 简介
1. 读写分离&读写分离 简介 主从同步延迟 分配机制 解决单点故障 总结 2. 主从复制&读写分离 搭建 搭建主从复制(双主) 搭建读写分离 1. 读写分离&读写分离 简介 ...
- Mysql主从配置,实现读写分离
大型网站为了软解大量的并发访问,除了在网站实现分布式负载均衡,远远不够.到了数据业务层.数据访问层,如果还是传统的数据结构,或者只是单单靠一台服务器扛,如此多的数据库连接操作,数据库必然会崩溃,数据丢 ...
- 黄聪:Mysql主从配置,实现读写分离
大型网站为了软解大量的并发访问,除了在网站实现分布式负载均衡,远远不够.到了数据业务层.数据访问层,如果还是传统的数据结构,或者只是单单靠一台服务器扛,如此多的数据库连接操作,数据库必然会崩溃,数据丢 ...
- redis 主从复制+读写分离+哨兵
1.redis读写分离应用场景 当数据量变得庞大的时候,读写分离还是很有必要的.同时避免一个redis服务宕机,导致应用宕机的情况,我们启用sentinel(哨兵)服务,实现主从切换的功能.redis ...
- linux下mysql多实例安装
1.MySQL多实例介绍 1.1.什么是MySQL多实例 MySQL多实例就是在一台机器上开启多个不同的服务端口(如:3306,3307),运行多个MySQL服务进程,通过不同的socket监听不同的 ...
- mysql多实例安装与ssl认证
mysql多实例安装有两种形式: 同一数据库版本的多实例安装. 不同数据库版本的多实例安装. 同一数据库的多实例安装: 在同一台机器上安装4台mysql数据库实例. 从官网下载MySQL5.6版本的二 ...
- linux下mysql多实例安装(转)
转自:http://www.cnblogs.com/xuchenliang/p/6843990.html 1.MySQL多实例介绍 1.1.什么是MySQL多实例 MySQL多实例就是在一台机器上 ...
随机推荐
- java 处理word文档 (含图片,表格内容)
因为本人长期从事Oa相关项目的开发,所以处理word文档,Pdf,Excel等是在所难免的. 1.需求 处理Excel 能够用jxl 或者poi 2需求 用户在系统上填 ...
- 如何在 Linux 上安装应用程序
如何在 Linux 上安装应用程序 编译自:https://opensource.com/article/18/1/how-install-apps-linux作者: Seth Kenlon原创:LC ...
- 对win2012 server 虚拟机hyper-V 硬盘管理,容量变更及新增硬盘
目的:对win2012 server 虚拟机hyper-V 硬盘管理,容量变更及新增硬盘 一.压缩虚拟机硬盘容量 进入Server 2012的操作系统,打开CMD框,输入:diskmgmt.msc,回 ...
- BZOJ一句话
一句话题解集合. 1061: [Noi2008]志愿者招募 单纯形,运用对偶原理转化过来,变成标准形然后单纯性裸上即可. #include<cmath> #include<cstdi ...
- BZOJ1194: [HNOI2006]潘多拉的盒子(tarjan)
Description 传说中,有个神奇的潘多拉宝盒.如果谁能打开,便可以拥有幸福.财富.爱情.可是直到真的打开,才发现与之 相随的还有灾难.不幸.其实,在潘多拉制造这个宝盒的时候,设置了一些咒语来封 ...
- 洛谷 P1732 [TJOI2011]序列
P1732 [TJOI2011]序列 题目描述 一指数列A={a1, a2, …, an},根据数列A计算数列B={b1, b2, …, bn},其中: 求\sum\limits^n_{i=1} b_ ...
- ADB高级应用
ADB高级应用 一.利用无线来查看adb shell > adb tcpip 5555 连接: > adb connect IP:5555 见后文<调试注意事项> 二.模拟按键 ...
- Android_L(64bit) 模拟器配置及创建项目
Android L可能就是Android 5.0.随之而来的还有Android Watch. Android TV. 而据说在10月中旬也就是15号Google的公布会上应该会推出Nexus 6和Ne ...
- C++对象模型——Inline Functions(第四章)
4.5 Inline Functions 以下是Point class 的一个加法运算符的可能实现内容: class Point { friend Point operator+(const Poin ...
- rtsp和sdp协议简介
RTSP是由Real network 和Netscape共同提出的如何有效地在IP网络上传输流媒体数据的应用层协议. 实时流协议(RTSP)建立并控制一个或几个时间同步的连续流媒体,如音频和视频.尽管 ...