时间:2021-07-01 10:21:17 帮助过:23人阅读
[root@localhost-m(252) /usr/local/src]# mysqldump -uroot -p123456 --single-transaction  --master-data=2   -E -R   --ignore-table=mysql.*  --flush-logs -A  >/r2/bak_sql/all_20171201.sql
[root@localhost-m(252) /usr/local/src]# cd /r2/bak_sql/
[root@localhost-m(252) /r2/bak_sql]# ls -lsh
total 102M
102M -rw-r--r-- 1 root root 102M 12月  1 17:16 all_20171201.sql
[root@localhost-m(252) /r2/bak_sql]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[root@localhost-m(252) /r2/bak_sql]# ps -ef |grep mysqld
root     105281  82231  0 18:19 pts/4    00:00:00 grep --color=auto mysqld
升级失败回退时使用)-- 在实例关闭之后,通过 cp datadir 目录的方式来备份。
[root@localhost-m(252) /r2/bak_sql]# cd /r2/
[root@localhost-m(252) /r2]# mv mysqldata mysqldatabak
1、安装 MySQL 5.7
[root@localhost-m(252) /usr/local/src]# pwd
/usr/local/src
[root@localhost-m(252) /usr/local/src]# ll |grep mysql
-rw-r--r--  1 root  root  654430368 12月  1 16:05 mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
drwxr-xr-x 14 mysql mysql      4096 7月  31 17:03 zabbix-3.2.7
[root@localhost-m(252) /usr/local/src]# mv  /usr/local/mysql  /usr/local/mysql5.5
[root@localhost-m(252) /usr/local/src]# md5sum  mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz  --校验tar包MD5与官网MD5对比是否正确
ebc8cbdaa9c356255ef82bd989b07cfb  mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
[root@localhost-m(252) /usr/local/src]# tar zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
mysql-5.7.18-linux-glibc2.5-x86_64/bin/myisam_ftdump
mysql-5.7.18-linux-glibc2.5-x86_64/bin/myisamchk
......
mysql-5.7.18-linux-glibc2.5-x86_64/docs/INFO_SRC
[root@localhost-m(252) /usr/local]# ll |grep mysql
drwxr-xr-x. 13 root   root    4096 3月   9  2016 mysql5.5
drwxr-xr-x   9 root   root    4096 12月  4 09:18 mysql-5.7.18-linux-glibc2.5-x86_64
[root@localhost-m(252) /usr/local]# ln -s mysql-5.7.18-linux-glibc2.5-x86_64 mysql
[root@localhost-m(252) /usr/local]# ll |grep mysql
lrwxrwxrwx   1 root   root      34 12月  4 09:20 mysql -> mysql-5.7.18-linux-glibc2.5-x86_64
drwxr-xr-x. 13 root   root    4096 3月   9  2016 mysql5.5
drwxr-xr-x   9 root   root    4096 12月  4 09:18 mysql-5.7.18-linux-glibc2.5-x86_642、修改相关目录的权限
[root@localhost-m(252) /usr/local]# chown -R mysql.mysql mysql
[root@localhost-m(252) /usr/local]# chown -R mysql.mysql mysql-5.7.18-linux-glibc2.5-x86_643、检查改环境变量
[root@localhost-m(252) /r2/mysqldata]# which mysql
/usr/local/mysql/bin/mysql
--如何没有,在/etc/profile 文件中的添加export PATH=/usr/local/mysql/bin:$PATH
使用 source /etc/profile 刷新配置
[root@localhost-m(252) /r2/mysqldata]# source /etc/profile
[root@localhost-m(252) /r2/mysqldata]# which mysql
/usr/local/mysql/bin/mysql1、修改 my.cnf 配置文件
[root@localhost-m(252) /usr/local]# cp /etc/my.cnf /r2/mysqldatabak/my_5.5.33.cnf     --备份配置文件
my.cnf配置文件
# line:        V1.4
# mail:         gczheng@139.com    
# data:         2017-12-04
# file_name:    my.cnf
[client]
port    = 3306
socket  = /r2/mysqldata/mysql.sock
#=======================================================================
# # MySQL客户端配置
#=======================================================================
[mysql]
prompt="(\u@\h) \\R:\\m:\\s [\d]> "
no-auto-rehash
#=======================================================================
# MySQL服务器全局配置
#=======================================================================
[mysqld]
user = mysql
port = 3306
server-id = 48168
tmpdir = /r2/mysqldata
datadir = /r2/mysqldata
socket  = /r2/mysqldata/mysql.sock
wait_timeout = 31536000
#interactive_timeout = 600
sql_mode =
#sql_mode 配置为空值
skip_name_resolve = 1
lower_case_table_names = 0
character-set-server = utf8
#auto_increment_increment = 1
#auto_increment_offset = 1
log_timestamps = SYSTEM
init_connect=‘SET NAMES utf8‘
######################### 性能参数 ####################
open_files_limit = 1024000
max_connections = 10000
max_user_connections=9990
max_connect_errors = 100000
table_open_cache = 1024
max_allowed_packet = 128M
thread_cache_size = 64
max_heap_table_size = 32M
query_cache_type = 0
###global cache ###
key_buffer_size = 1G
query_cache_size = 0
###session cache ###
sort_buffer_size = 8M       #排序缓冲
join_buffer_size = 4M       #表连接缓冲
read_buffer_size = 8M       #顺序读缓冲
read_rnd_buffer_size = 8M   #随机读缓冲
tmp_table_size = 32M        #内存临时表
binlog_cache_size = 4M      #二进制日志缓冲
thread_stack = 256KB        #线程的堆栈的大小
######################### binlog设置 #####################
binlog_format = MIXED
log_bin = /r2/mysqldata/binlog
max_binlog_cache_size = 1G
max_binlog_size = 1G
expire_logs_days = 30
sync_binlog =1
######################### 复制设置 ########################
log_slave_updates=1
#replicate-do-db=User
#binlog-ignore-db = test
#slave-skip-errors=1146,1032,1062
### GTID 配置 ###
gtid_mode=ON
enforce-gtid-consistency=true
### 开启并行复制(从库) ####
#slave-parallel-type=LOGICAL_CLOCK     #基于组提交的并行复制方式
#slave-parallel-workers=24             #并行的SQL线程数量
#master-info_repository=TABLE          #master信息以表的形式保存
#relay_log_info_repository=TABLE       #slave信息以表的形式保存
#relay_log_recovery=ON                 #relay_log自我修复
######################### innodb ##########################
default_storage_engine = InnoDB
innodb_data_file_path = ibdata1:1G:autoextend
innodb_buffer_pool_size = 32G         #系统内存50%
innodb_open_files = 100000
innodb_flush_log_at_trx_commit = 1
innodb_file_per_table = 1
innodb_lock_wait_timeout = 5
#根据服务器IOPS能力适当调整innodb_io_capacity,一般配普通SSD盘的话,可以调整到 10000 - 20000
innodb_io_capacity = 10000
innodb_io_capacity_max = 20000
innodb_flush_method = O_DIRECT
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
innodb_large_prefix = 0
innodb_thread_concurrency = 64
innodb_strict_mode = OFF
innodb_sort_buffer_size = 4194304
### undolog设置 ###
innodb_undo_directory = /r2/undolog              #undolog日志目录
innodb_undo_tablespaces = 3                      #undolog日志文件个数
innodb_undo_logs = 128                           #回滚段的数量, 至少大于等于35,默认128。
innodb_max_undo_log_size = 1G                    #当超过这个阀值(默认是1G),会触发truncate回收(收缩)动作,truncate后空间缩小到10M。
innodb_purge_rseg_truncate_frequency = 128       #控制回收(收缩)undolog的频率
innodb_undo_log_truncate = 1                     #即开启在线回收undolog日志文件
######################### log 设置 #####################
log_error = /r2/mysqldata/error.log
slow_query_log = 1
long_query_time = 10
slow_query_log_file = /r2/mysqldata/slow.log
#=======================================================================
# MySQL mysqldump配置
#=======================================================================
[mysqldump]
quick
max_allowed_packet = 32M
#=======================================================================
# MySQL mysqld_safe配置
#=======================================================================
[mysqld_safe]
log_error = /r2/mysqldata/error.log
pid_file = /r2/mysqldata/mysqldb.pid2、配置MySQL目录和权限
[root@localhost-m(252) /usr/local]# mkdir -p /r2/mysqldata
[root@localhost-m(252) /usr/local]# cd /r2/mysqldata
[root@localhost-m(252) /r2/mysqldata]# mkdir -p /r2/undolog
[root@localhost-m(252) /r2/mysqldata]# chown -R mysql.mysql /r2/undolog
[root@localhost-m(252) /r2/mysqldata]# chown -R mysql.mysql /r2/mysqldata
[root@localhost-m(252) /r2/mysqldata]# ll /r2 |grep undolog
drwxr-xr-x  2 mysql mysql  4096 12月  4 10:57 undolog3、初始化MySQL和启动
[root@localhost-m(252) /r2/mysqldata]# /usr/local/mysql/bin/mysqld --initialize --user=mysql
--获取随机密码
[root@localhost-m(252) /r2/mysqldata]# grep password /r2/mysqldata/error.log
2017-12-04T11:00:12.112903+08:00 1 [Note] A temporary password is generated for root@localhost: ;YV-le1Y5UYa    
[root@localhost-m(252) /r2/mysqldata]# cat > /usr/lib/systemd/system/mysql.service <EOF
[Unit]
Description=Mysql
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
#PIDFile=/r2/mysqldata/mysqldb.pid
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecReload=/usr/local/mysql/support-files/mysql.server restart
ExecStop=/usr/local/mysql/support-files/mysql.server stop
LimitNOFILE = 65535
PrivateTmp=false
[Install]
WantedBy=multi-user.target
EOF
[root@localhost-m(252) /r2/mysqldata]# systemctl daemon-reload
[root@localhost-m(252) /r2/mysqldata]# systemctl start mysql
--确认是否启动成功
[root@localhost-m(252) /r2/mysqldata]# systemctl status mysql
● mysql.service - Mysql
   Loaded: loaded (/usr/lib/systemd/system/mysql.service; disabled; vendor preset: disabled)
   Active: active (running) since 一 2017-12-04 11:32:29 CST; 6s ago
  Process: 65996 ExecStart=/usr/local/mysql/support-files/mysql.server start (code=exited, status=0/SUCCESS)
 Main PID: 66004 (mysqld_safe)
   CGroup: /system.slice/mysql.service
           ├─66004 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/r2/mysqldata --pid-file=/r2/mysqldata/localhost.localdomain.pid
           └─66894 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/r2/mysqldata --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/r2/mysqldata/error.lo...
12月 04 11:32:26 localhost.localdomain systemd[1]: Starting Mysql...
12月 04 11:32:29 localhost.localdomain mysql.server[65996]: Starting MySQL... SUCCESS!
12月 04 11:32:29 localhost.localdomain systemd[1]: Started Mysql.
[root@localhost-m(252) /r2/mysqldata]# ps -ef | grep mysqld | grep -v grep
root      66004      1  0 11:32 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/r2/mysqldata --pid-file=/r2/mysqldata/localhost.localdomain.pid
mysql     66894  66004  1 11:32 ?        00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/r2/mysqldata --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/r2/mysqldata/error.log --open-files-limit=1024000 --pid-file=/r2/mysqldata/localhost.localdomain.pid --socket=/r2/mysqldata/mysql.sock --port=33064、添加MySQL自启动服务
[root@localhost-m(252) /r2/mysqldata]# systemctl enable mysql
Created symlink from /etc/systemd/system/multi-user.target.wants/mysql.service to /usr/lib/systemd/system/mysql.service.
[root@localhost-m(252) /r2/mysqldata]# systemctl list-unit-files |grep mysql
mysql.service                               enabled
pmm-mysql-metrics-42002.service             enabled
pmm-mysql-queries-0.service                 enabled
[root@localhost-m(252) /r2/mysqldata]#1、导入权限sql
--直接导入会报错,需要先修改root@localhost密码,然后再导入
[root@localhost-m(252) /r2/mysqldata]# mysql -uroot -p
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 784
Server version: 5.7.18-log MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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.
root@ipanel 11:45:  [(none)]> source /usr/local/src/grants.sql   
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.    --提示用alter user更改密码
root@ipanel 11:47:  [(none)]>  alter user root@localhost identified by ‘123456‘;   --更改随机密码
Query OK, 0 rows affected (0.00 sec)
root@ipanel 11:48:  [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
root@ipanel 11:48:  [(none)]> source /usr/local/src/grants.sql  --导入原来的账号密码,其中包括原来root账号密码
Query OK, 0 rows affected, 2 warnings (0.00 sec)
Query OK, 0 rows affected, 2 warnings (0.00 sec)
Query OK, 0 rows affected, 2 warnings (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected, 2 warnings (0.00 sec)
Query OK, 0 rows affected, 2 warnings (0.00 sec)
Query OK, 0 rows affected, 2 warnings (0.00 sec)
Query OK, 0 rows affected, 3 warnings (0.00 sec)
Query OK, 0 rows affected, 3 warnings (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.00 sec)
root@ipanel 11:48:  [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
root@ipanel 11:49:  [(none)]> select user,host,authentication_string from mysql.user;  
+-----------+-----------+-------------------------------------------+
| user      | host      | authentication_string                     |
+-----------+-----------+-------------------------------------------+
| root      | localhost | *xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |  
······
| operator  | localhost | **xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
+-----------+-----------+-------------------------------------------+
9 rows in set (0.00 sec)2、导入主库备份文件
[root@localhost-m(252) /r2/mysqldata]# mysql -uroot -pxxxxx </r2/bak_sql/all_20171201.sql
[root@localhost-m(252) /r2/mysqldata]# cat /r2/mysqldata/error.log |grep error
[root@localhost-m(252) /r2/mysqldata]# systemctl stop mysql
[root@localhost-m(252) /r2/mysqldata]# systemctl status mysql
● mysql.service - Mysql
   Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since 一 2017-12-04 14:58:57 CST; 10s ago
  Process: 80083 ExecStop=/usr/local/mysql/support-files/mysql.server stop (code=exited, status=0/SUCCESS)
 Main PID: 66004 (code=exited, status=0/SUCCESS)
12月 04 11:32:26 localhost.localdomain systemd[1]: Starting Mysql...
12月 04 11:32:29 localhost.localdomain mysql.server[65996]: Starting MySQL... SUCCESS!
12月 04 11:32:29 localhost.localdomain systemd[1]: Started Mysql.
12月 04 14:58:44 localhost.localdomain systemd[1]: Stopping Mysql...
12月 04 14:58:57 localhost.localdomain mysql.server[80083]: Shutting down MySQL............. SUCCESS!
12月 04 14:58:57 localhost.localdomain systemd[1]: Stopped Mysql.
[root@localhost-m(252) /r2/mysqldata]# systemctl start mysql
[root@localhost-m(252) /r2/mysqldata]# systemctl status mysql
● mysql.service - Mysql
   Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; vendor preset: disabled)
   Active: active (running) since 一 2017-12-04 14:59:18 CST; 1s ago
  Process: 80083 ExecStop=/usr/local/mysql/support-files/mysql.server stop (code=exited, status=0/SUCCESS)
  Process: 80207 ExecStart=/usr/local/mysql/support-files/mysql.server start (code=exited, status=0/SUCCESS)
 Main PID: 80215 (mysqld_safe)
   CGroup: /system.slice/mysql.service
           ├─80215 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/r2/mysqldata --pid-file=/r2/mysqldata/localhost.localdomain.pid
           └─81105 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/r2/mysqldata --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/r2/mysqldata/error.lo...
12月 04 14:59:15 localhost.localdomain systemd[1]: Starting Mysql...
12月 04 14:59:18 localhost.localdomain mysql.server[80207]: Starting MySQL... SUCCESS!
12月 04 14:59:18 localhost.localdomain systemd[1]: Started Mysql.4、升级完成,清除权限文件后,请跳过步骤II(回滚),直接进入步骤III
[root@localhost-m(252) /r2/mysqldata]# rm /usr/local/src/grants.sql
rm: remove regular file ‘/usr/local/src/grants.sql’? Y
1、关闭数据库
[root@localhost-m(252) /r2/mysqldata]# systemctl stop mysql
[root@localhost-m(252) /r2/mysqldata]# ps -ef |grep mysqld
root      85807  64413  0 16:13 pts/0    00:00:00 grep --color=auto mysqld2、恢复5.5.33数据目录
[root@localhost-m(252) /r2]# pwd
/r2
[root@localhost-m(252) /r2]# mv mysqldata mysqldata57bak
[root@localhost-m(252) /r2]# mv mysqldatabak mysqldata
[root@localhost-m(252) /r2]# cp /etc/my.cnf mysqldata57bak/my.cnf
[root@localhost-m(252) /r2]# cp mysqldata/my.cnf  /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[root@localhost-m(252) /r2]# cd /usr/local/
[root@localhost-m(252) /usr/local]# ll |grep mysql
lrwxrwxrwx   1 mysql  mysql     34 12月  4 09:20 mysql -> mysql-5.7.18-linux-glibc2.5-x86_64  --mysql链接5.7
drwxr-xr-x. 13 root   root    4096 3月   9  2016 mysql5.5
drwxr-xr-x   9 mysql  mysql   4096 12月  4 09:18 mysql-5.7.18-linux-glibc2.5-x86_64
-- 删除5.7 mysql链接
[root@localhost-m(252) /usr/local]# rm mysql
rm: remove symbolic link ‘mysql’? y
[root@localhost-m(252) /usr/local]# ll |grep mysql
drwxr-xr-x. 13 root   root    4096 3月   9  2016 mysql5.5
drwxr-xr-x   9 mysql  mysql   4096 12月  4 09:18 mysql-5.7.18-linux-glibc2.5-x86_64
--重建5.5.33 链接
[root@localhost-m(252) /usr/local]# ln -s mysql5.5 mysql
[root@localhost-m(252) /usr/local]# ll |grep mysql
lrwxrwxrwx   1 root   root       8 12月  4 16:19 mysql -> mysql5.5    --mysql链接到5.5
drwxr-xr-x. 13 root   root    4096 3月   9  2016 mysql5.5
drwxr-xr-x   9 mysql  mysql   4096 12月  4 09:18 mysql-5.7.18-linux-glibc2.5-x86_64
--重新授权软件目录权限
[root@localhost-m(252) /usr/local]# chown -R mysql.mysql /usr/local/mysql
[root@localhost-m(252) /usr/local]# chown -R mysql.mysql /usr/local/mysql5.5
[root@localhost-m(252) /usr/local]# ll |grep mysql
lrwxrwxrwx   1 mysql  mysql      8 12月  4 16:19 mysql -> mysql5.5
drwxr-xr-x. 13 mysql  mysql   4096 3月   9  2016 mysql5.5
drwxr-xr-x   9 mysql  mysql   4096 12月  4 09:18 mysql-5.7.18-linux-glibc2.5-x86_64
--重新授权数据目录权限
[root@localhost-m(252) /usr/local]# chown -R mysql.mysql /r2/mysqldata
[root@localhost-m(252) /usr/local]# ll /r2/ |grep mysqldata
drwxr-xr-x 64 mysql mysql  4096 12月  4 16:28 mysqldata
drwxr-xr-x 53 mysql mysql 12288 12月  4 16:16 mysqldata57bak
[root@localhost-m(252) /usr/local]# systemctl start mysql
[root@localhost-m(252) /usr/local]# systemctl status mysql
● mysql.service - Mysql
   Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; vendor preset: disabled)
   Active: active (running) since 一 2017-12-04 16:28:15 CST; 5s ago
  Process: 89752 ExecStart=/usr/local/mysql/support-files/mysql.server start (code=exited, status=0/SUCCESS)
 Main PID: 89764 (mysqld_safe)
   CGroup: /system.slice/mysql.service
           ├─89764 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/r2/mysqldata --pid-file=/r2/mysqldata/localhost.localdomain.pid
           └─90233 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/r2/mysqldata --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/r2/mysqldata/localhos...
12月 04 16:28:13 localhost.localdomain systemd[1]: Starting Mysql...
12月 04 16:28:15 localhost.localdomain mysql.server[89752]: Starting MySQL.. SUCCESS!
12月 04 16:28:15 localhost.localdomain systemd[1]: Started Mysql.
[root@localhost-m(252) /usr/local]# ps -ef |grep mysqld |grep -v grep
root      89764      1  0 16:28 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/r2/mysqldata --pid-file=/r2/mysqldata/localhost.localdomain.pid
mysql     90233  89764  0 16:28 ?        00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/r2/mysqldata --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/r2/mysqldata/localhost.localdomain.err --pid-file=/r2/mysqldata/localhost.localdomain.pid --socket=/r2/mysqldata/mysql.sock --port=3306
[root@localhost-m(252) /usr/local]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.33-log Source distribution
Copyright (c) 2000, 2013, 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>
例如:主库(192.68.48.168)和从库(192.168.24.180)
1、从库(192.168.24.180)
从库my.cnf添加并行复制参数,修改server-id=2
### 开启并行复制(从库) ####
slave-parallel-type=LOGICAL_CLOCK     #基于组提交的并行复制方式
slave-parallel-workers=24             #并行的SQL线程数量
master-info_repository=TABLE          #master信息以表的形式保存
relay_log_info_repository=TABLE       #slave信息以表的形式保存
relay_log_recovery=ON                 #relay_log自我修复2、建立主从复制
[root@proxy r2]# cd bak_sql/
[root@proxy bak_sql]# scp 192.168.48.168:/r2/bak_sql/all_20171201.sql ./
[root@proxy ~]# mysql -uroot -p
(root@localhost) 19:15:50 [(none)]> source /r2/bak_sql/all_20171201.sql
(root@localhost) 20:01:14 [(none)]> change master to
-> master_host=‘192.168.48.168‘,
-> master_user=‘repl‘,
-> master_password=‘repl‘,
-> master_auto_position = 1;
Query OK, 0 rows affected, 2 warnings (0.02 sec)
(root@localhost) 20:04:49 [(none)]> start slave;
Query OK, 0 rows affected (0.09 sec)
(root@localhost) 20:04:55 [(none)]> show slave status \G;
*************************** 1. row ***************************
               Slave_IO_State: Queueing master event to the relay log
                  Master_Host: 192.168.48.168
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: binlog.000002
          Read_Master_Log_Pos: 139295376
               Relay_Log_File: proxy-relay-bin.000002
                Relay_Log_Pos: 81035047
        Relay_Master_Log_File: binlog.000002
             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: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 81034840
              Relay_Log_Space: 139295790
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 10279
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 1
                  Master_UUID: 3eae5854-d89f-11e7-ab20-246e960a8d84
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Waiting for dependent transaction to commit
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set: 3eae5854-d89f-11e7-ab20-246e960a8d84:1-2476
            Executed_Gtid_Set: 3eae5854-d89f-11e7-ab20-246e960a8d84:1-1408,
9dc847d8-bf72-11e7-9ec4-000c2998e4f1:1-2845713
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.01 sec)
ERROR:
No query specified
--slave启动了24个线程(Waiting for an event from Coordinator)
(root@localhost) 15:34:15 [(none)]> show processlist;
+----+-------------+-----------+------+---------+---------+--------------------------------------------------------+------------------+
| Id | User        | Host      | db   | Command | Time    | State                                                  | Info             |
+----+-------------+-----------+------+---------+---------+--------------------------------------------------------+------------------+
|  4 | system user |           | NULL | Connect | 1366166 | Waiting for master to send event                       | NULL             |
|  5 | system user |           | NULL | Connect | 1364215 | Slave has read all relay log; waiting for more updates | NULL             |
|  6 | system user |           | NULL | Connect |     843 | Waiting for an event from Coordinator                  | NULL             |
|  7 | system user |           | NULL | Connect |   12366 | Waiting for an event from Coordinator                  | NULL             |
|  8 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
|  9 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 10 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 11 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 12 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 13 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 14 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 15 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 16 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 17 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 18 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 19 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 20 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 21 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 22 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 23 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 24 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 25 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 26 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 27 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 28 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 29 | system user |           | NULL | Connect | 1366166 | Waiting for an event from Coordinator                  | NULL             |
| 49 | root        | localhost | NULL | Query   |       0 | starting                                               | show processlist |
+----+-------------+-----------+------+---------+---------+--------------------------------------------------------+------------------+
27 rows in set (0.00 sec)
--主库
mysql> create database tttt;
Query OK, 1 row affected (0.00 sec)
mysql> create table tttt.aa(a int);
Query OK, 0 rows affected (0.05 sec)
mysql> insert into tttt.aa values(1);
Query OK, 1 row affected (0.00 sec)
mysql> insert into tttt.aa values(2);
Query OK, 1 row affected (0.00 sec)
mysql> select * from tttt.aa;
+------+
| a    |
+------+
|    1 |
|    2 |
+------+
2 rows in set (0.00 sec)
mysql> update tttt.aa set a=10 where a =1;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> delete from  tttt.aa where a =2;
Query OK, 1 row affected (0.00 sec)
mysql> select * from tttt.aa;
+------+
| a    |
+------+
|   10 |
+------+
1 row in set (0.00 sec)
--从库
(root@localhost) 15:39:28 [(none)]> select * from tttt.aa;
+------+
| a    |
+------+
|   10 |
+------+
1 row in set (0.00 sec)
2.5、 drop 测试库
mysql> drop database tttt;
Query OK, 1 row affected (0.06 sec)
主库
(root@localhost) 10:04:08 [(none)]> show master status \G;
*************************** 1. row ***************************
             File: binlog.000004
         Position: 38701778
     Binlog_Do_DB:
 Binlog_Ignore_DB:
Executed_Gtid_Set: 3eae5854-d89f-11e7-ab20-246e960a8d84:1-7887
1 row in set (0.00 sec)
ERROR:
No query specified
(root@localhost) 10:04:08 [(none)]> show master status \G;
*************************** 1. row ***************************
             File: binlog.000004
         Position: 41768570                                         --当数据写入binlog pos点一直在变
     Binlog_Do_DB:
 Binlog_Ignore_DB:
Executed_Gtid_Set: 3eae5854-d89f-11e7-ab20-246e960a8d84:1-7890      --GTID值也在变化
1 row in set (0.00 sec)
ERROR:
No query specified
(root@localhost) 10:04:21 [(none)]> show master status \G;
*************************** 1. row ***************************
             File: binlog.000004
         Position: 43813112
     Binlog_Do_DB:
 Binlog_Ignore_DB:
Executed_Gtid_Set: 3eae5854-d89f-11e7-ab20-246e960a8d84:1-7892
1 row in set (0.00 sec)
从库
(root@localhost) 12:10:37 [(none)]> show slave status \G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.48.168
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: binlog.000004
          Read_Master_Log_Pos: 105168419
               Relay_Log_File: proxy-relay-bin.000004
                Relay_Log_Pos: 105168472
        Relay_Master_Log_File: binlog.000004
             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: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 105168265
              Relay_Log_Space: 105170645
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 1
                  Master_UUID: 3eae5854-d89f-11e7-ab20-246e960a8d84
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set: 3eae5854-d89f-11e7-ab20-246e960a8d84:1-7952
            Executed_Gtid_Set: 3eae5854-d89f-11e7-ab20-246e960a8d84:1-7952,
9dc847d8-bf72-11e7-9ec4-000c2998e4f1:1-2845713
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.00 sec)
ERROR:
No query specified
(root@localhost) 12:10:48 [(none)]> show slave status \G;
*************************** 1. row ***************************