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多实例就是在一台机器上 ...
随机推荐
- jQuery插件开发初探
最简单的插件 $.fn.changeStyle = function (colorStr) { $(this).css('color',colorStr); } 应用如下: <!DOCTYPE ...
- CORS support in Spring Framework--官方
原文地址:https://spring.io/blog/2015/06/08/cors-support-in-spring-framework For security reasons, browse ...
- Java 开发 2.0: 现实世界中的 Redis
原文地址:http://www.ibm.com/developerworks/cn/java/j-javadev2-22/ 之前,我已在本系列中讨论过 NoSQL 的概念,也介绍了一些与 Java 平 ...
- Python正则表达式初识(十)附正则表达式总结
今天分享正则表达式最后一个特殊字符“\d”,具体的教程如下. 1.特殊字符“\d”十分常用,其代表的意思是数字.代码演示如下图所示. 其中“+”的意思是表示连续,在这里代表的意思是连续的数字.但是输出 ...
- 关于servlet的web.xml映射
1.原理 <servlet> <!-- servlet的名字,随便起个名,但和下面的servlet名一致 --> <servlet-name>hello</s ...
- selenium使用报错“selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.”
安装了python3,使用pip安装了selenium,但是在使用时,报了“selenium.common.exceptions.WebDriverException: Message: 'gecko ...
- [Parcel] Bundle a React App with Parcel
Parcel comes in as the new cool kid in the bundlers world. Unlike other bundlers which take lots of ...
- 在OEL 5.4 32bit上使用yum install命令遇到的问题
在OEL 5.4 32bit上使用yum install命令遇到的问题 [root@localhost yum.repos.d]# yum install elfutils-libelf-devel- ...
- UIButton文字居左显示
题外话:时间依然过的非常快.不知不觉2015年就过去一半了.感觉自己好像没有大的改变.仅仅能感叹时间飞逝,却不能有所收获. 我从来都不是一个安于现状的人,改变自己的想法从未停止过.我想大多数人都跟我有 ...
- ip6tables: ipv6-icmp vs icmp
ip6tables: ipv6-icmp vs icmp资料来源 https://www.jethrocarr.com/2013/02/09/ip6tables-ipv6-icmp-vs-icmp/I ...