Mysql主从复制的实现
MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQL AB公司。MySQL被广泛地应用在Internet上的中小型网站中。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库。Mysql内建的复制功能是构建大型、高性能应用程序的基础;将Mysql的数据分布到多个系统上,而这种分布的机制是通过将一台Mysql服务器的数据复制到其他主机(slave)上,由slave主机读取Master服务器的二进制日志文件然后重新在本地执行一遍来实现。做Mysql主从复制时,所有更新操作都只能在Master服务器,而Slave服务只负责更新自己的数据并提供查询操作。
Mysql复制主要能解决的有问题有:数据的分布、负载均衡、数据备份、高可用以及容错性。
Mysql的复制原理基本上可以分为以下3步:
1.在Master服务器将改变的数据记录到二进制日志(binary log)中(这些记录叫做二进制日志事件)
2.Slave服务器将Master服务器上的二进制日志拷贝到自己的中继日志(relay-log)中
3.Slave服务器读取中继日志中的事件,然后将改变的数据写入到自己的数据库中
第1步:在Master服务器上记录二进制日志。在每个更新数据的事务完成之前,Master服务器都会将数据更改记录到二进制日志中。即使事务在执行期间是交错的,Mysql也会串行地将事务写入到二进制日志中。在把事件写入二进制日志之后,Master服务器告诉存储引擎可以提交事务了
第2步:Slave服务器把主服务器的二进制日志拷贝到自己的硬盘上,进入所谓的“中继日志”中。首先,它启动一个工作线程,叫I/O线程,这个I/O线程开启一个普通的客户端连接,然后启动一个特殊的二进制日志转储进程(它没有相应的SQL命令)。这个转储进程Master服务器的二进制日志中读取数据。它不会对事件进行轮询。如果3跟上了Master服务器,就会进入休眠状态并等待有新的事件发生时Master服务器发出的信号。I/O线程把数据写入Slave服务器的中继日志中
第3步:SQL线程读取中继日志,并且重放其中的事件,然后更新Slave服务器的数据。由于这个线程能跟上I/O线程,中继日志通常在操作系统的缓存中,所以中继日志的开销很低。SQL线程执行事件也可以被写入Slave服务器自己的二进制日志中,它对于有些场景很实用
上图中显示了在Slave服务器有两个运行的线程,在Master服务器上也有一个运行的线程:和其他普通连接一样,由Slave服务器发起的连接,在Master服务器上同样拥有一个线程。
系统环境及拓扑
系统版本:CentOS 6.3_x86_64
Mysql版本:mysql-5.6.17
下载地址:http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.17.tar.gz
1.准备工作
1.1修改master、slave主机名
master主机名:mysql_master
slave主机名:mysql_slave
1.2在master和slave上配置主机名解析
# cat >> /etc/hosts << EOF
172.16.10.72 mysql_master master
172.16.10.61 mysql_slave slave
EOF
1.3时间同步
# yum install -y ntpdate
# ntpdate ntp.fudan.edu.cn
# crontab -e
* * * * /usr/sbin/ntpdate ntp.fudan.edu.cn
2.安装Mysql(master与slave分别进行)
# groupadd mysql
# useradd -s /sbin/nologin -g mysql mysql
# tar xf mysql-5.6..tar.gz
# cd mysql-5.6.# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
# make && make install# chown -R mysql.mysql /usr/local/mysql
# cd /usr/local/mysql/scripts/
# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data #初始化mysql数据库,#指定mysql数据文件的存放位置
# cd ..
# cd support-files/# cp mysql.server /etc/rc.d/init.d/mysql
# cp my-default.cnf /etc/my.cnf
# chkconfig --add mysql
# chkconfig mysql on
# service mysql start
Starting MySQL..... SUCCESS!# ln -s /usr/local/mysql/bin/* /usr/bin/
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql遇到报错如下:
- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake: (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake: (FIND_CURSES)
cmake/readline.cmake: (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt: (MYSQL_CHECK_EDITLINE)
-- Configuring incomplete, errors occurred!
解决办法:
yum -y install ncurses-devel
[root@mysql_master ~]# mysql
mysql> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* to eivll0m@'172.16.10.61' IDENTIFIED by 'password';
Query OK, rows affected (0.10 sec)
mysql> FLUSH PRIVILEGES;
Query OK, rows affected (0.06 sec)
mysql> SHOW GRANTS FOR eivll0m@'172.16.10.61';
+---------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for eivll0m@172.16.10.61 |
+---------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'eivll0m'@'172.16.10.61' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' |
+---------------------------------------------------------------------------------------------------------------------------------------------------+
row in set (0.02 sec)
3.2在Slave服务器上使用授权用户连接测试
[root@mysql_slave ~]# mysql -ueivll0m -ppassword -h 172.16.10.72
Warning: Using a password on the command line interface can be insecure.
ERROR (HY000): Can't connect to MySQL server on '172.16.10.72' (113) #报错原因为master服务器iptables阻止了slave的连接,暂时先关闭即可 [root@mysql_slave ~]# mysql -ueivll0m -ppassword -h 172.16.10.72
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6. Source distribution Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
3.3编辑master上的my.cnf,修改或增加以下内容:
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port =
server_id =
socket = /tmp/mysql.sock
log-bin = mysql-bin
log_bin_index = mysql_bin.index
binlog_format = mixed
innodb_flush_log_at_trx_commit=
重启mysqld服务
[root@mysql_master ~]# service mysqld restart
3.4编辑slave上的my.cnf,修改或增加以下内容:
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port =
server_id =
socket = /tmp/mysql.sock
skip_slave_start =
read_only =
relay_log = relay_log
relay_log_index = relay_log.index
重启mysqld服务
[root@mysql_slave ~]# service mysqld restart
3.5.查看master服务器的二进制日志及二进制日志事件位置
[root@mysql_master ~]# mysql -e 'SHOW MASTER STATUS;'
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin. | | | | |
+------------------+----------+--------------+------------------+-------------------+
File:表示从此日志开始复制
Position:表示从这个事件开始复制
3.6在Slave服务器上同步Master服务器上面的数据
mysql> CHANGE MASTER TO MASTER_HOST='mysql_master',MASTER_USER='eivll0m',MASTER_PASSWORD='password',MASTER_PORT=,MASTER_LOG_FILE='mysql-bin.000003',MASTER_LOG_POS=,MASTER_CONNECT_RETRY=;
3.7启动slave服务器的复制线程并查看状态
mysql> START SLAVE;
mysql> SHOW SLAVE STATUS\G;
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: mysql_master
Master_User: eivll0m
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: relay_log.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 988cd54d-c1a7-11e3-b1a5-000c29c976ef
Master_Info_File: /usr/local/mysql/data/master.info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position:
row in set (0.00 sec)
3.8在slave服务器查看启动的线程
[root@mysql_slave ~]# mysql -e 'SHOW PROCESSLIST;'
+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+------------------+
| | system user | | NULL | Connect | | Waiting for master to send event | NULL |
| | system user | | NULL | Connect | | Slave has read all relay log; waiting for the slave I/O thread to update it | NULL |
| | root | localhost | NULL | Query | | init | SHOW PROCESSLIST |
+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+------------------+
3.9验证:在saster服务器创建数据库,在slave服务器上验证是否复制过去
[root@mysql_master ~]# mysql -e 'CREATE DATABASE eivll0m;'
[root@mysql_master ~]# mysql -e 'SHOW DATABASES;'
+--------------------+
| Database |
+--------------------+
| information_schema |
| eivll0m |
| mysql |
| performance_schema |
| test |
+--------------------+
[root@mysql_slave ~]# mysql -e 'SHOW DATABASES;' #可以看到eimll0m数据库已经复制过去
+--------------------+
| Database |
+--------------------+
| information_schema |
| eivll0m |
| mysql |
| performance_schema |
| test |
+--------------------+
3.10在主从服务器查看二进制日志事件位置是否更新
[root@mysql_master ~]# mysql -e 'SHOW MASTER STATUS;'
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin. | | | | |
+------------------+----------+--------------+------------------+-------------------+
[root@mysql_slave ~]# mysql -e 'SHOW SLAVE STATUS\G;' | grep "Read_Master_Log_Pos"
Read_Master_Log_Pos:
由此可见,已经更新。
4.配置基于SSL的复制
由于Mysql的主从复制是明文传送的,如果在生产环境中跨网络使用主从还是明文传送,就无法保证数据的传输安全性,为了解决这一问题,我们需要加密进行传送,也就是基于SSL的加密方法进行传输数据。
4.1在master服务器搭建CA服务器
[root@mysql_master ~]# cd /etc/pki/CA/
[root@mysql_master CA]# (umask ;openssl genrsa -out private/cakey.pem )
[root@mysql_master CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name ( letter code) [XX]:CN
State or Province Name (full name) []:BeiJing
Locality Name (eg, city) [Default City]:ChaoYang
Organization Name (eg, company) [Default Company Ltd]:eivll0m
Organizational Unit Name (eg, section) []:Tech
Common Name (eg, your name or your server's hostname) []:mysql_master
Email Address []:master@eivll0m.com
[root@mysql_master CA]# touch index.txt
[root@mysql_master CA]# echo > serial
4.2为master创建证书申请并由CA服务器签发证书
[root@mysql_master ~]# mkdir /usr/local/mysql/ssl
[root@mysql_master ssl]# cd /usr/local/mysql/ssl
[root@mysql_master ssl]# (umask ;openssl genrsa -out master.key )
[root@mysql_master ssl]# openssl req -new -key master.key -out master.csr -days
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name ( letter code) [XX]:CN
State or Province Name (full name) []:BeiJing
Locality Name (eg, city) [Default City]:ChaoYang
Organization Name (eg, company) [Default Company Ltd]:eivll0m
Organizational Unit Name (eg, section) []:Tech
Common Name (eg, your name or your server's hostname) []:mysql_master
Email Address []:master@eivll0m.com Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@mysql_master ssl]# openssl ca -in master.csr -out master.crt -days
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: (0x1)
Validity
Not Before: Apr :: GMT
Not After : Apr :: GMT
Subject:
countryName = CN
stateOrProvinceName = BeiJing
organizationName = eivll0m
organizationalUnitName = Tech
commonName = mysql_master
emailAddress = master@eivll0m.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
A7:4D::::CD::5E::2A:8E:A6:::6A:AB:FA:::
X509v3 Authority Key Identifier:
keyid:0F::D1:B8:1C::4B::A6::9F:B4:6D:A3:C7::AA::5E: Certificate is to be certified until Apr :: GMT ( days)
Sign the certificate? [y/n]:y out of certificate requests certified, commit? [y/n]y
Write out database with new entries
Data Base Updated
4.3为slave服务器创建证书申请
[root@mysql_slave ~]# mkdir /usr/local/mysql/ssl
[root@mysql_slave ~]# cd /usr/local/mysql/ssl
[root@mysql_slave ~]# (umask ;openssl genrsa -out slave.key )
[root@mysql_slave ssl]# openssl req -new -key slave.key -out slave.csr -days
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name ( letter code) [XX]:CN
State or Province Name (full name) []:BeiJing
Locality Name (eg, city) [Default City]:ChaoYang
Organization Name (eg, company) [Default Company Ltd]:eivll0m
Organizational Unit Name (eg, section) []:Tech
Common Name (eg, your name or your server's hostname) []:mysql_slave
Email Address []: Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
4.4为slave服务器签署证书
[root@mysql_slave ssl]# scp slave.csr mysql_master:/tmp/
[root@mysql_master ssl]# openssl ca -in /tmp/slave.csr -out /tmp/slave.crt -days
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: (0x2)
Validity
Not Before: Apr :: GMT
Not After : Apr :: GMT
Subject:
countryName = CN
stateOrProvinceName = BeiJing
organizationName = eivll0m
organizationalUnitName = Tech
commonName = mysql_slave
emailAddress = slave@eivll0m.com
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
B9:4B:EA::0E:9E:4B::A6:9A:4E::3B:DF:B3:B9:E3:E9:ED:
X509v3 Authority Key Identifier:
keyid:0F::D1:B8:1C::4B::A6::9F:B4:6D:A3:C7::AA::5E: Certificate is to be certified until Apr :: GMT ( days)
Sign the certificate? [y/n]:y out of certificate requests certified, commit? [y/n]y
Write out database with new entries
Data Base Updated
在mastet服务器上将签署好证书申请拷贝到Slave服务器
[root@mysql_master ~]# scp /tmp/slave.crt mysql_slave:/usr/local/mysql/ssl/
4.5将CA证书拷贝到slave服务器与saster相应目录
[root@mysql_master ~]# scp /etc/pki/CA/cacert.pem mysql_slave:/usr/local/mysql/ssl/
[root@mysql_master ~]# cp /etc/pki/CA/cacert.pem /usr/local/mysql/ssl/
4.6修改master与slave服务器证书属主、属组为"mysql"用户
# chown -R mysql.mysql /usr/local/mysql/ssl
# ll /usr/local/mysql/ssl/
-rw-r--r-- mysql mysql Sep : cacert.pem
-rw-r--r-- mysql mysql Sep : master.crt
-rw-r--r-- mysql mysql Sep : master.csr
-rw------- mysql mysql Sep : master.key
4.7在master与slave服务器编辑my.cnf开启SSL加密功能
在master服务器的my.cnf文件中[mysqld]下添加如下参数
ssl #开启SSL功能
ssl_ca = /usr/local/mysql/ssl/cacert.pem #指定CA文件位置
ssl_cert = /usr/local/mysql/ssl/master.crt #指定证书文件位置
ssl_key = /usr/local/mysql/ssl/master.key #指定密钥所在位置
在slave服务器的my.cnf文件中[mysqld]下添加如下参数
ssl
ssl_ca = /usr/local/mysql/ssl/cacert.pem
ssl_cert = /usr/local/mysql/ssl/slave.crt
ssl_key = /usr/local/mysql/ssl/slave.key
4.8在master服务器查看SSL加密是否开启并创建授权一个基于密钥认证的用户
mysql> SHOW VARIABLES LIKE '%ssl%';
+---------------+---------------------------------+
| Variable_name | Value |
+---------------+---------------------------------+
| have_openssl | YES |
| have_ssl | YES |
| ssl_ca | /usr/local/mysql/ssl/cacert.pem |
| ssl_capath | |
| ssl_cert | /usr/local/mysql/ssl/master.crt |
| ssl_cipher | |
| ssl_crl | |
| ssl_crlpath | |
| ssl_key | /usr/local/mysql/ssl/master.key |
+---------------+---------------------------------+
rows in set (0.12 sec)
mysql> GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* to 'slave'@'172.16.%.%' IDENTIFIED BY 'passwd' REQUIRE SSL;
Query OK, rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, rows affected (0.02 sec)
4.9查看master服务器二进制日志文件和事件位置
mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin. | | | | |
+------------------+----------+--------------+------------------+-------------------+
row in set (0.09 sec)
4.10在slave上测试使用加密用户指定密钥连接master服务器(如下测试成功)
root@mysql_slave ssl]# mysql -uslave -ppasswd -h 172.16.10.72 --ssl-ca=/usr/local/mysql/ssl/cacert.pem --ssl-cert=/usr/local/mysql/ssl/slave.crt --ssl-key=/usr/local/mysql/ssl/slave.key
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-log Source distribution Copyright (c) , , Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
4.11查看slave服务器SSL是否开启并连接master服务器
mysql> SHOW VARIABLES LIKE '%ssl%';
+---------------+---------------------------------+
| Variable_name | Value |
+---------------+---------------------------------+
| have_openssl | YES |
| have_ssl | YES |
| ssl_ca | /usr/local/mysql/ssl/cacert.pem |
| ssl_capath | |
| ssl_cert | /usr/local/mysql/ssl/master.crt |
| ssl_cipher | |
| ssl_crl | |
| ssl_crlpath | |
| ssl_key | /usr/local/mysql/ssl/master.key |
+---------------+---------------------------------+
mysql> change master to master_host='172.16.10.72',master_user='slave',master_password='passwd',master_log_file='mysql-bin.000007',master_log_pos=,master_ssl=,master_ssl_ca='/usr/local/mysql/ssl/cacert.pem',master_ssl_cert='/usr/local/mysql/ssl/slave.crt',master_ssl_key='/usr/local/mysql/ssl/slave.key';
mysql> start slave; #启动IO线程
mysql> show slave status\G; ##查看slave状态
4.12查看slave服务器状态
[root@mysql_slave ~]# cd /usr/local/mysql/ssl/
[root@mysql_slave ssl]# mysql -e 'show slave status\G;'
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.10.72
Master_User: slave
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos: 919
Relay_Log_File: relay_log.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos: 919
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: Yes
Master_SSL_CA_File: /usr/local/mysql/ssl/cacert.pem
Master_SSL_CA_Path:
Master_SSL_Cert: /usr/local/mysql/ssl/slave.crt
Master_SSL_Cipher:
Master_SSL_Key: /usr/local/mysql/ssl/slave.key
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
Master_UUID: 988cd54d-c1a7-11e3-b1a5-000c29c976ef
Master_Info_File: /usr/local/mysql/data/master.info
SQL_Delay:
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count:
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position:
4.13创建数据库进行验证
[root@mysql_master ssl]# mysql -e 'create database mydata'
[root@mysql_master ssl]# mysql -e 'show databases'
+--------------------+
| Database |
+--------------------+
| information_schema |
| eivll0m |
| mydata |
| mysql |
| performance_schema |
| test |
+--------------------+
[root@mysql_slave data]# mysql -e 'show databases;'
+--------------------+
| Database |
+--------------------+
| information_schema |
| eivll0m |
| mydata |
| mysql |
| performance_schema |
| test |
+--------------------+
复制成功!
Mysql主从复制的实现的更多相关文章
- MySQL主从复制(Master-Slave)实践
MySQL数据库自身提供的主从复制功能可以方便的实现数据的多处自动备份,实现数据库的拓展.多个数据备份不仅可以加强数据的安全性,通过实现读写分离还能进一步提升数据库的负载性能. 下图就描述了一个多个数 ...
- 2.快速部署MySQL主从复制
1.快速部署MySQL主从复制 [root@mysql ~]# mysql -uroot -p123456 -S /data/3307/mysql.sock -e "show slave ...
- MySQL 主从复制与读写分离概念及架构分析
1.MySQL主从复制入门 首先,我们看一个图: 影响MySQL-A数据库的操作,在数据库执行后,都会写入本地的日志系统A中. 假设,实时的将变化了的日志系统中的数据库事件操作,在MYSQL-A的33 ...
- MySQL主从复制原理及配置详细过程以及主从复制集群自动化部署的实现
一.复制概述 Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台主机的数据复制到其它主机(slaves)上,并重 ...
- MySQL主从复制
Mysql主从复制介绍 MySQL支持单向.双向.链式级联.实时.异步复制.在复制过程中,一台服务器充当服务器(Master),而一个或多个其它的服务器充当从服务器(Slave). 复制可以是单向:M ...
- mysql主从复制实现数据库同步
mysql主从复制相信已经用得很多了,但是由于工作原因一直没怎么用过.趁着这段时间相对空闲,也就自己实现一遍.尽管互联网上已有大把类似的文章,但是自身实现的仍然值得记录. 环境: 主服务器:cento ...
- mysql主从复制配置
使用mysql主从复制的好处有: 1.采用主从服务器这种架构,稳定性得以提升.如果主服务器发生故障,我们可以使用从服务器来提供服务. 2.在主从服务器上分开处理用户的请求,可以提升数据处理效率. 3. ...
- 【大型网站技术实践】初级篇:搭建MySQL主从复制经典架构
一.业务发展驱动数据发展 随着网站业务的不断发展,用户量的不断增加,数据量成倍地增长,数据库的访问量也呈线性地增长.特别是在用户访问高峰期间,并发访问量突然增大,数据库的负载压力也会增大,如果架构方案 ...
- Mysql主从复制,读写分离(mysql-proxy),双主结构完整构建过程
下面介绍MySQL主从复制,读写分离,双主结构完整构建过程,不涉及过多理论,只有实验和配置的过程. Mysql主从复制(转载请注明出处,博文地址:) 原理是master将改变记录到二进制日志(bina ...
- MySQL主从复制中常见的3个错误及填坑方案
一.问题描述 主从复制错误一直是MySQL DBA一直填不完的坑,如鲠在喉,也有人说mysql主从复制不稳定云云,其实MySQL复制比我们想象中要坚强得多,而绝大部分DBA却认为只要跳过错误继续复制就 ...
随机推荐
- WPF自定义控件之带倒计时的按钮--Button
1.说明 之前做过一个小项目,点击按钮,按钮进入倒计时无效状态,计时完成后,恢复原样,现在就实现该效果---带倒计时的按钮 2.效果 1)正常状态 2)MouseOver( ...
- angular service/directive
<html class=" js cssanimations csstransitions" ng-app="phonecatApp" > < ...
- 文件/图片,批量上传【神器】--WebUploader
<system.web> <httpRuntime maxRequestLength="102400" executionTimeout="720&qu ...
- 使用Yeoman搭建 AngularJS 应用 (12) —— 让我们搭建一个网页应用
原文地址:http://yeoman.io/codelab/local-storage.html 安装Bower程序包 我们使用另一个Angular模块,"angular-local-sto ...
- shell复习---文件解压命令
需要自己部署服务端,故在申请了空间之后,需要自己安装linux自己,自己安装Apache等,所以下载的压缩文件需要运行.网上找了一些解压命令不对,特别试了下面的方法有效,特别记录一下: 用ssh 登陆 ...
- (转)基于即时通信和LBS技术的位置感知服务(三):搭建Openfire服务器+测试2款IM客户端
主要包含4个章节: 1. Java 领域的即时通信的解决方案 2. 搭建 Openfire 服务器 3. 使用客户端测试我们搭建的 Openfire 服务器 4. Smack 和 ASmack 一.J ...
- css3属性整理
浏览器内核:主流内容主要有Mozilla(熟悉的有Firefox,Flock等浏览器).WebKit(熟悉的有Safari.Chrome等浏览器).Opera(Opera浏览器).Trident(讨厌 ...
- 2013流行Python项目汇总
2013流行Python项目汇总 转自:http://www.kankanews.com/ICkengine/archives/102963.shtml Python作为程序员的宠儿,越来越得到人们的 ...
- JAVA面试题:String 堆内存和栈内存
java把内存划分为两种:一种是栈(stack)内存,一种是堆(heap)内存 在函数中定义的一些基本类型的变量和对象的引用变量都在栈内存中分配,当在一段代码块定义一个变量时,java就在栈中为这个变 ...
- POJ1260Pearls
http://poj.org/problem?id=1260 题意 :这个题大概是讲,给你几种等级不同的珠宝,然后告诉你它的数量和价值,等级是升序排列的,且随等级的升高价值也随之升高,但为了防止有的客 ...