MySQL 多实例部署

1.下载安装包

[root@localhost ~]# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz[root@localhost ~]# ls
anaconda-ks.cfg  mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz

2.解压至/usr/local

[root@localhost ~]# tar -xf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# ls /usr/local/
bin  etc  games  include  lib  lib64  libexec  mysql-5.7.35-linux-glibc2.12-x86_64  sbin  share  src

3.做mysql目录的软连接,并更改其属主属组

[root@localhost local]# ln -sv mysql-5.7.35-linux-glibc2.12-x86_64/ mysql
"mysql" -> "mysql-5.7.35-linux-glibc2.12-x86_64/"
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 2 root root   6 4月  11 2018 bin
drwxr-xr-x. 2 root root   6 4月  11 2018 etc
drwxr-xr-x. 2 root root   6 4月  11 2018 games
drwxr-xr-x. 2 root root   6 4月  11 2018 include
drwxr-xr-x. 2 root root   6 4月  11 2018 lib
drwxr-xr-x. 2 root root   6 4月  11 2018 lib64
drwxr-xr-x. 2 root root   6 4月  11 2018 libexec
lrwxrwxrwx. 1 root root  36 8月  27 12:42 mysql -> mysql-5.7.35-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 8月  27 12:41 mysql-5.7.35-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root   6 4月  11 2018 sbin
drwxr-xr-x. 5 root root  49 4月  21 19:36 share
drwxr-xr-x. 2 root root   6 4月  11 2018 src[root@localhost local]# chown -R mysql.mysql mysql
[root@localhost local]# ll -d mysql
lrwxrwxrwx. 1 mysql mysql 36 8月  29 05:50 mysql -> mysql-5.7.35-linux-glibc2.12-x86_64/

4.环境变量

[root@localhost local]# vim /etc/profile.d/mysql.sh
[root@localhost local]# cat /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@localhost local]# source /etc/profile.d/mysql.sh
[root@localhost local]# which mysql
/usr/local/mysql/bin/mysql

5.创建各实例存放的目录

[root@localhost ]# mkdir -p /opt/data/{3306,3307,3308}
[root@localhost ]# ls /opt/data/
3306  3307  3308

6.初始化各个实例

3306

[root@localhost profile.d]#  mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2021-08-29T10:22:56.524466Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-08-29T10:22:56.692402Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-08-29T10:22:56.721919Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-08-29T10:22:56.777888Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 13e7f1c7-08b3-11ec-aed0-000c2988823d.
2021-08-29T10:22:56.778394Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-08-29T10:22:57.784376Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2021-08-29T10:22:57.784497Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2021-08-29T10:22:57.784999Z 0 [Warning] CA certificate ca.pem is self signed.
2021-08-29T10:22:57.842963Z 1 [Note] A temporary password is generated for root@localhost: ;ahco8p#)#L,//保存临时密码
[root@localhost data]# echo ';ahco8p#)#L,' > 06passwd

3307

[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/3307
2021-08-27T12:10:22.121228Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-08-27T12:10:23.371094Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-08-27T12:10:23.551015Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-08-27T12:10:23.988171Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c1eaa7e8-072f-11ec-8eee-000c2978b180.
2021-08-27T12:10:23.991268Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-08-27T12:10:25.006022Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2021-08-27T12:10:25.006044Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2021-08-27T12:10:25.014096Z 0 [Warning] CA certificate ca.pem is self signed.
2021-08-27T12:10:25.139118Z 1 [Note] A temporary password is generated for root@localhost: OpCs&?ILf0z)//保存临时密码
[root@localhost ~]# echo 'OpCs&?ILf0z)' > 3307_passwd

3308

[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/3308
2021-08-27T12:11:08.680649Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-08-27T12:11:10.064525Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-08-27T12:11:10.267492Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-08-27T12:11:10.356165Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: dd8ddb31-072f-11ec-9185-000c2978b180.
2021-08-27T12:11:10.357696Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-08-27T12:11:11.694578Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2021-08-27T12:11:11.694596Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2021-08-27T12:11:11.695690Z 0 [Warning] CA certificate ca.pem is self signed.
2021-08-27T12:11:12.272690Z 1 [Note] A temporary password is generated for root@localhost: nGpdhZUu;48q//存储临时密码
[root@loecho 'nGpdhZUu;48q' > 3308_passwd

查看存储的三个临时密码

[root@localhost ~]# ls
3306_passwd  3308_passwd        mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
3307_passwd  anaconda-ks.cfg

7.安装perl,查看依赖包是否安装

[root@localhost ~]# yum -y install install perl
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile* base: mirrors.cn99.com* extras: mirrors.tuna.tsinghua.edu.cn* updates: mirrors.cn99.com[root@localhost ~]# ldd /usr/local/mysql/bin/mysqllinux-vdso.so.1 =>  (0x00007ffecdbfb000)libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f543b00b000)librt.so.1 => /lib64/librt.so.1 (0x00007f543ae03000)libdl.so.2 => /lib64/libdl.so.2 (0x00007f543abff000)libncurses.so.5 => /lib64/libncurses.so.5 (0x00007f543a9d8000)libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f543a6d0000)libm.so.6 => /lib64/libm.so.6 (0x00007f543a3ce000)libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f543a1b8000)libc.so.6 => /lib64/libc.so.6 (0x00007f5439deb000)libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007f5439bc1000)/lib64/ld-linux-x86-64.so.2 (0x00007f543b227000

8.编辑/etc/my.cnf配置文件

[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin[mysqld3306]
datadir = /opt/data/3306
port = 3306
socket = /tmp/3306.sock
pid-file = /opt/date/3306/mysql.pid
log-error = /var/log/mysql_3306.log[mysqld3307]
datadir = /opt/data/3307
port = 3307
socket = /tmp/3307.sock
pid-file = /opt/date/3307/mysql.pid
log-error = /var/log/mysql_3307.log[mysqld3308]
datadir = /opt/data/3308
port = 3308
socket = /tmp/3308.sock
pid-file = /opt/date/3308/mysql.pid
log-error = /var/log/mysql_3308.log

9.更改密码、


[root@localhost ~]# cat 3306_pass
cc6s;of>kf)[root@localhost ~]# mysql -uroot -p'cc6s;of>kf)' -h127.0.0.1 -h3306
mysql: [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 3
Server version: 5.7.22Copyright (c) 2000, 2018, 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> set password = password('1');
Query OK, 0 rows affected, 1 warning (0.01 sec)[root@localhost ~]# cat 3307_pass
Cdp5'dmz;ao[root@localhost ~]# mysql -uroot -pCdp5'dmz;ao -h127.0.0.1 -p3307
mysql: [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 3
Server version: 5.7.22Copyright (c) 2000, 2018, 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> set password = password('2');
Query OK, 0 rows affected, 1 warning (0.01 sec)[root@localhost ~]# cat 3308_pass
3d5fl)f9rtf[root@localhost ~]# mysql -uroot -p'3d5fl)f9rtf' -h127.0.0.1 -P3308
mysql: [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 2
Server version: 5.7.35Copyright (c) 2000, 2021, Oracle and/or its affiliates.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> set password = password('3');
Query OK, 0 rows affected, 1 warning (0.00 sec)

10.设置开机自启

//将服务文件拷贝到init.d下,并重命名为mysql
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld//
[root@localhost ~]# ECHO export PATH=/usr/local/mysql/bin:$PATH > /etc/init.d/mysqld//赋予可执行权限
[root@localhost ~]# chmod +x /etc/init.d/mysqld//添加服务
[root@localhost ~]# chkconfig --add mysqld//启动
[root@localhost ~]# ss -antl
State  Recv-Q Send-Q  Local Address:Port   Peer Address:Port
LISTEN 0      128           0.0.0.0:22          0.0.0.0:*
LISTEN 0      80                  *:3306              *:*
LISTEN 0      128              [::]:22             [::]:*                                                       

Xtrabackup

Xtrabackup介绍

Xtrabackup是由percona开源的免费数据库热备份软件,它能对InnoDB数据库和XtraDB存储引擎的数据库非阻塞地备份(对于MyISAM的备份同样需要加表锁);mysqldump备份方式是采用的逻辑备份,其最大的缺陷是备份和恢复速度较慢,如果数据库大于50G,mysqldump备份就不太适合。

Xtrabackup安装完成后有4个可执行文件,其中2个比较重要的备份工具是innobackupex、xtrabackup

1)xtrabackup 是专门用来备份InnoDB表的,和mysql server没有交互;

2)innobackupex 是一个封装xtrabackup的Perl脚本,支持同时备份innodb和myisam,但在对myisam备份时需要加一个全局的读锁。

3)xbcrypt 加密解密备份工具

4)xbstream 流传打包传输工具,类似tar

Xtrabackup优点

1)备份速度快,物理备份可靠

2)备份过程不会打断正在执行的事务(无需锁表)

3)能够基于压缩等功能节约磁盘空间和流量

4)自动备份校验

5)还原速度快

6)可以流传将备份传输到另外一台机器上

7)在不增加服务器负载的情况备份数据

Xtrabackup备份原理

备份开始时首先会开启一个后台检测进程,实时检测mysq redo的变化,一旦发现有新的日志写入,立刻将日志记入后台日志文件xtrabackup_log中,之后复制innodb的数据文件一系统表空间文件ibdatax,复制结束后,将执行flush tables with readlock,然后复制.frm MYI MYD等文件,最后执行unlock tables,最终停止xtrabackup_log

输出如下提示信息

xtrabackup: Transaction log of lsn (2543172) to (2543181) was copied.

171205 10:17:52 completed OK!

Xtrabackup增量备份介绍

xtrabackup增量备份的原理是:

1)、首先完成一个完全备份,并记录下此时检查点LSN;

2)、然后增量备份时,比较表空间中每个页的LSN是否大于上次备份的LSN,若是则备份该页并记录当前检查点的LSN。

增量备份优点:

1)、数据库太大没有足够的空间全量备份,增量备份能有效节省空间,并且效率高;

2)、支持热备份,备份过程不锁表(针对InnoDB而言),不阻塞数据库的读写;

3)、每日备份只产生少量数据,也可采用远程备份,节省本地空间;

4)、备份恢复基于文件操作,降低直接对数据库操作风险;

5)、备份效率更高,恢复效率更高。

实例

下载安装xtrabackup

[root@localhost ~]# yum -y install percona-xtrabackup-2.3.10-1.el7.x86_64.rpm
[root@localhost ~]# ls
anaconda-ks.cfg
percona-x
[root@localhost ~]# yum -y install percona-xtrabackup-2.3.10-1.el7.x86_64.rpm//进行备份与恢复
[root@localhost ~]# innobackupex --user=root--password=xym /opt/mysqlbackup/full/MySQL binlog position:filename 'mysql-bin.000004', position '107'210827 21:03:23 [00]Writing backup-my.cnf210827  21:03:23 [00]        ...done210827 21:03:23 [00]Writing xtrabackup_info210827  21:03:23 [00]        ...donextrabackup: Transactionlog of lsn (1595675) to (1595675) was copied.210827  21:03:24 completedOK!//查看全量备份的文件
[root@localhost ~]# ls /opt/mysqlbackup/full  2021-08-29_20-01-06[root@localhost ~]# ls /opt/mysqlbackup/full/2021-08-29_20-01-06/backup-my.cnf  mysql               xtrabackup_binlog_info  xtrabackup_infoibdata1        performance_schema  xtrabackup_checkpoints  xtrabackup_logfile//备份数据库的用户需要具有相应权限.
[root@localhost ~]mysql -uroot -pxym
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.35Copyright (c) 2000, 2021, Oracle and/or its affiliates.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> create user 'bkpuser'@'localhost'identified by '123456';Query OK, 0 rows affected(0.06 sec)mysql> revoke all privileges,grantoption from 'bkpuser'@'localhost';Query OK, 0 rows affected(0.00 sec)mysql>  grant reload,lock tables,replication client,process on *.* to 'bkpuser'@'localhost';Query OK, 0 rows affected(0.00 sec)mysql> flush privileges;Query OK, 0 rows affected(0.05 sec)//创建数据库 表 插入数据
mysql> create database xym;Query OK, 1 row affected(0.00 sec)mysql> use xym;Database changedmysql> create table 1 (id int,name char(16) not null);Query OK, 0 rows affected(0.05 sec)mysql> insert into 1 values(1,'caiaochen');Query OK, 1 row affected(0.02 sec)mysql> insert into 1 values(2,'xk');Query OK, 1 row affected(0.02 sec)mysql> select * from tb1;+------+----------+| id   | name    |+------+----------+|    1 | caiaochen ||    2 | xk        |+------+----------+2 rows in set (0.00 sec)mysql> quitBye//增量备份二进制文件
[root@localhost ~]# mysqlbinlog --start-position=107 /usr/local/mysql/data/mysql-bin.000004> /opt/mysqlbackup/inc/`date +%F`.sql//执行误操作删库
[root@localhost ~]# rm -rf /usr/local/mysql/data/* //准备全备的redo日志
[root@localhost ~]# innobackupex --apply-log/opt/mysqlbackup/full/2021-08-29_20-01-06/.........InnoDB: File './ibtmp1'size is now 12 MB.InnoDB: 96 redo rollbacksegment(s) found. 1 redo rollback segment(s) are active.InnoDB: 32 non-redorollback segment(s) are active.InnoDB: 5.7.13 started;log sequence number 1595925xtrabackup: startingshutdown with innodb_fast_shutdown = 1InnoDB: FTS optimizethread exiting.InnoDB: Startingshutdown...InnoDB: Shutdowncompleted; log sequence number 1595944210827 21:33:32 completedOK!//使用innobakupex命令的 --copy-back 进行拷贝
[root@localhost ~]# innobackupex --copy-back/opt/mysqlbackup/full/2021-08-29_20-01-06///修改属主属组
[root@localhost ~]# chown -R mysql:mysql/usr/local/mysql/data///关闭二进制文件
mysql> set sql_log_bin=0;Query OK, 0 rows affected(0.00 sec)//读取增量备份文件
mysql> source/opt/mysqlbackup/inc/2021-08-29.sqlQuery OK, 0 rows affected(0.00 sec)Query OK, 0 rows affected(0.00 sec)Query OK, 0 rows affected(0.00 sec)Query OK, 0 rows affected (0.00sec)mysql> set sql_log_bin=1;Query OK, 0 rows affected(0.00 sec)mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || xym                || mysql              || performance_schema |+--------------------+4 rows in set (0.00 sec)mysql> use xym;Database changedmysql> select * from 1;+------+----------+| id   | name     |+------+----------+|    1 | caiaochen||    2 | xk       |+------+----------+2 rows in set (0.01 sec)

MySQL 多实例部署 xtrabackup备份与恢复相关推荐

  1. mysql数据库备份与恢复,mysql多实例部署

    mysql数据库备份与恢复,mysql多实例部署 文章目录 mysql数据库备份与恢复,mysql多实例部署 1: 数据库备份 2:冷备份 3:热备份 4:mysql备份工具mysqldump 5:差 ...

  2. mysql 多实例部署、xtrabackup下载与安装

    mysql 多实例部署 一. 二进制安装mysql 软件下载 下载网络源 curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyu ...

  3. MYSQl 多实例部署

    MYSQl 多实例部署和 Xtarbackup 软件下载安装 下载二进制格式的mysql软件包 [root@localhost ~]# cd /usr/src/ [root@localhost ~]# ...

  4. mysql多实例部署

    二进制文件下载 [root@localhost ~]# cd /usr/src/ [root@localhost src]# wget https://downloads.mysql.com/arch ...

  5. mysql 单实例部署_Mysql 数据库单机多实例部署手记

    最近的研发机器需要部署多个环境,包括数据库.为了管理方便考虑将mysql数据库进行隔离,即采用单机多实例部署的方式. 找了会资料发现用的人也不是太多,一般的生产环境为了充分发挥机器性能都是单机单实例运 ...

  6. 04 MySQL多实例部署

    软件下载 //下载二进制格式的mysql软件包 [root@localhost ~]# cd /usr/src/ [root@localhost src]# wget https://download ...

  7. mysql 单实例部署_MySQL 5.5单实例 编译安装

    1.建立MySQL账号 首先以root登录到Linux,然后执行如下命令创建MySQL组及用户[root@loveyu home]# groupadd mysql [root@loveyu home] ...

  8. mysql差异备份与多实例部署

    mysql差异备份与多实例部署 文章目录 差异备份与恢复 mysql多实例部署 差异备份与恢复 差异备份简单来说就是备份自上一次完整备份之后有变化的数据 //开启mysql服务的二进制日志功能 [ro ...

  9. 多实例部署、开机自启、xtrabackup备份与恢复

    多实例部署.开机自启.xtrabackup备份与恢复 一.MySQL多实例部署 1 下载二进制包 wget http://https://dev.mysql.com/get/Downloads/MyS ...

最新文章

  1. 19.VS属性管理器窗口不见了怎么办?
  2. Linux echo命令和查看环境变量实例
  3. visual studio 代码提示插件_请收好:10 个实用的 VS Code 插件
  4. 中国厨房家具行业消费需求调查与品牌格局分析报告2022版
  5. linux(centos)搭建SVN服务器
  6. jio文件 久其_功能强大的Windows文件管理器工具
  7. 文本分类有哪些论文中很少提及却对性能有重要影响的tricks?
  8. Lua游戏开发----游戏搭建
  9. Qt总结之三:磁盘文件操作、遍历文件夹和文件目录,并过滤和获取文件信息、后缀名、前缀名(三)
  10. SpringBoot + Eureka启动失败
  11. selenium处理动态加载数据
  12. Pam x86_64 and i686 have conflicting man pages
  13. 红linux系统,红帽linux系统官方下载-红帽linux系统32位v9.0 完整版 - 极光下载站
  14. 遗传算法应用于XGBoost的调参过程
  15. win 10 硬盘安装 ubuntu 18.04
  16. 从多个PDF中快速搜索字符串
  17. Manifest merger failed with multiple errors问题解决
  18. 用Python 处理文本数据
  19. 快嘴雅虎通群发 官方
  20. jQuery05(插件)

热门文章

  1. 数字化和全链信息化助力服装供应链智能化发展
  2. Oracle中Clob类型处理解析
  3. Round robin
  4. 前端构建3D建模知识(css,html)
  5. 计算机大赛主题板报,中小学电脑制作大赛电子板报优秀作品国学.ppt
  6. Eclipse设置编码字体、左侧窗口字体、控制台字体
  7. 2021年度总结,一整年的精华所在!
  8. Manifest基本
  9. 一个序列的子序列个数
  10. MTK开发之—添加aw21024 i2c设备驱动