MySQL多实例安装部署

MySQL多实例安装部署

1、MySQL多实例概念

多实例就是在一台服务器上同时开启多个不同的数据库服务端口(例如3306、3307),同时运行多个MYSQL服务进程,这些服务进程通过不同的 socket监听不同的服务端口来提供服务。

优点

MySQL多实例,可以通过多个端口向用户提供服务,充分利用一台服务器的闲置资源

缺点

无论是多少个端口提供服务,但始终使用的是一台服务器的资源,所以当访问量过大时,依然存在 高并发的问题

2、mysql 多实例部署

2.1 软件下载
#下载二进制格式的mysql软件包
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
2.2 配置用户和组并解压二进制程序至/usr/local下
#创建mysql用户和组
[root@localhost src]# useradd -r -M -s /sbin/nologin mysql
[root@localhost src]# id mysql
uid=994(mysql) gid=991(mysql) groups=991(mysql)

#解压软件至/usr/local/
[root@localhost src]# tar -xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# ls /usr/local/
bin  games    lib    libexec                              sbin   src
etc  include  lib64  mysql-5.7.37-linux-glibc2.12-x86_64  share

#设置软链接
[root@localhost local]# ln -sv mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.37-linux-glibc2.12-x86_64/'
[root@localhost local]# ll
total 0
drwxr-xr-x. 2 root root   6 May 19  2020 bin
drwxr-xr-x. 2 root root   6 May 19  2020 etc
drwxr-xr-x. 2 root root   6 May 19  2020 games
drwxr-xr-x. 2 root root   6 May 19  2020 include
drwxr-xr-x. 2 root root   6 May 19  2020 lib
drwxr-xr-x. 3 root root  17 Jul 23 21:08 lib64
drwxr-xr-x. 2 root root   6 May 19  2020 libexec
lrwxrwxrwx. 1 root root  36 Jul 29 01:58 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 root root 129 Jul 29 01:55 mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root   6 May 19  2020 sbin
drwxr-xr-x. 5 root root  49 Jul 23 21:08 share
drwxr-xr-x. 2 root root   6 May 19  2020 src

#修改目录/usr/local/mysql*的属主属组
[root@localhost local]# chown -R mysql.mysql mysql*
[root@localhost local]# ll
total 0
drwxr-xr-x. 2 root  root    6 May 19  2020 bin
drwxr-xr-x. 2 root  root    6 May 19  2020 etc
drwxr-xr-x. 2 root  root    6 May 19  2020 games
drwxr-xr-x. 2 root  root    6 May 19  2020 include
drwxr-xr-x. 2 root  root    6 May 19  2020 lib
drwxr-xr-x. 3 root  root   17 Jul 23 21:08 lib64
drwxr-xr-x. 2 root  root    6 May 19  2020 libexec
lrwxrwxrwx. 1 mysql mysql  36 Jul 29 01:58 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 mysql mysql 129 Jul 29 01:55 mysql-5.7.37-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root  root    6 May 19  2020 sbin
drwxr-xr-x. 5 root  root   49 Jul 23 21:08 share
drwxr-xr-x. 2 root  root    6 May 19  2020 src

#添加环境变量
[root@localhost local]#  echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@localhost local]# source /etc/profile.d/mysql.sh
[root@localhost local]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin

#配置头文件—include,库文件—lib,man文件

a).头文件—include
[root@localhost mysql]# ln -s /usr/local/mysql/include/ /usr/include/mysql
[root@localhost mysql]# ldconfig

b).库文件—lib
[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib/

c).man文件
[root@localhost mysql]# vim /etc/man_db.conf
......

MANDATORY_MANPATH                       /usr/local/mysql/man
......

2.3 创建各实例数据存放的目录
[root@localhost ~]# mkdir -p /opt/data/{3306,3307,3308}
[root@localhost ~]# chown -R mysql.mysql /opt/data/
[root@localhost ~]# ll /opt/data/
total 0
drwxr-xr-x. 2 mysql mysql 6 Jul 29 02:08 3306
drwxr-xr-x. 2 mysql mysql 6 Jul 29 02:08 3307
drwxr-xr-x. 2 mysql mysql 6 Jul 29 02:08 3308
2.4 初始化各实例
#初始化3306实例
[root@localhost ~]#  mysqld --initialize --user mysql --datadir /opt/data/3306
2022-07-28T18:10:55.688238Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2022-07-28T18:10:55.870431Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-28T18:10:55.900700Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2022-07-28T18:10:55.958646Z 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: 9ff5a837-0ea0-11ed-8af7-000c29e16842.

2022-07-28T18:10:55.959533Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2022-07-28T18:10:56.479019Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.

2022-07-28T18:10:56.479035Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.

2022-07-28T18:10:56.479478Z 0 [Warning] CA certificate ca.pem is self signed.

2022-07-28T18:10:56.541878Z 1 [Note] A temporary password is generated for root@localhost: glUI5k%_eY0)
[root@localhost ~]# echo 'glUI5k%_eY0)' > 3306_passwd

#初始化3307实例
[root@localhost ~]#  mysqld --initialize --user mysql --datadir /opt/data/3307
2022-07-28T18:13:08.002396Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2022-07-28T18:13:08.190046Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-28T18:13:08.216254Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2022-07-28T18:13:08.220706Z 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: eecb3f15-0ea0-11ed-89c1-000c29e16842.

2022-07-28T18:13:08.221521Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2022-07-28T18:13:08.894461Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.

2022-07-28T18:13:08.894488Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.

2022-07-28T18:13:08.894929Z 0 [Warning] CA certificate ca.pem is self signed.

2022-07-28T18:13:09.105418Z 1 [Note] A temporary password is generated for root@localhost: s3#Y-hhyBKve
[root@localhost ~]# echo 's3#Y-hhyBKve' > 3307_passwd

#初始化3308实例
[root@localhost ~]#  mysqld --initialize --user mysql --datadir /opt/data/3308
2022-07-28T18:13:53.110334Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2022-07-28T18:13:53.283030Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-28T18:13:53.308723Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2022-07-28T18:13:53.364947Z 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: 09b3b5f7-0ea1-11ed-926a-000c29e16842.

2022-07-28T18:13:53.365788Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2022-07-28T18:13:54.027096Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.

2022-07-28T18:13:54.027135Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.

2022-07-28T18:13:54.027592Z 0 [Warning] CA certificate ca.pem is self signed.

2022-07-28T18:13:54.447992Z 1 [Note] A temporary password is generated for root@localhost: (+d7r!3v%lVe
[root@localhost ~]# echo '(+d7r!3v%lVe' > 3308_passwd
2.5 安装perl
[root@localhost ~]# yum -y install perl
2.6 配置配置文件/etc/my.cnf
[root@localhost ~]# vim /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/mysql3306.sock
pid-file = /opt/data/3306/mysql_3306.pid
log-error=/var/log/3306.log

[mysqld3307]
datadir = /opt/data/3307
port = 3307
socket = /tmp/mysql3307.sock
pid-file = /opt/data/3307/mysql_3307.pid
log-error=/var/log/3307.log

[mysqld3308]
datadir = /opt/data/3308
port = 3308
socket = /tmp/mysql3308.sock
pid-file = /opt/data/3308/mysql_3308.pid
log-error=/var/log/3308.log
2.7 启动各实例
[root@localhost ~]# mysqld_multi start 3306
[root@localhost ~]# mysqld_multi start 3307
[root@localhost ~]# mysqld_multi start 3308
[root@localhost ~]# ss -antl
State     Recv-Q    Send-Q       Local Address:Port       Peer Address:Port   Process
LISTEN    0         128                0.0.0.0:22              0.0.0.0:*
LISTEN    0         128                   [::]:22                 [::]:*
LISTEN    0         80                       *:3306                  *:*
LISTEN    0         80                       *:3307                  *:*
LISTEN    0         80                       *:3308                  *:*
2.8 初始化各实例密码
#3306初始密码
[root@localhost ~]# cat 3306_passwd
glUI5k%_eY0)
[root@localhost ~]# mysql -p'glUI5k%_eY0)' -S /tmp/mysql3306.sock
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.37

Copyright (c) 2000, 2022, 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('Passwd123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye

#3307初始密码
[root@localhost ~]# cat 3307_passwd
s3#Y-hhyBKve
[root@localhost ~]# mysql -p's3#Y-hhyBKve' -S /tmp/mysql3307.sock
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.37

Copyright (c) 2000, 2022, 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('Passwd123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit;
Bye

#3308初始密码
[root@localhost ~]# cat 3308_passwd
(+d7r!3v%lVe
[root@localhost ~]# mysql -p'(+d7r!3v%lVe' -S /tmp/mysql3308.sock
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.37

Copyright (c) 2000, 2022, 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('Passwd123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit;
Bye

Original: https://www.cnblogs.com/Alone-8712/p/16530901.html
Author: Alone-林
Title: MySQL多实例安装部署

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/578542/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • 在Ubuntu20.04上安装Kubernetes-Kubeadm和Minikube

    镜像下载、域名解析、时间同步请点击阿里云开源镜像站 在本文中,我们将了解如何在 Ubuntu 20.04 上安装 Kubernetes。在过去的几年里,容器化为开发人员提供了很大的…

    Linux 2023年5月27日
    0108
  • Web前端基础精品入门(HTML+CSS+JavaScript+JS)[爱前端]听课笔记3:三角形的制作

    菜单中有的项目有夏季菜单,需要添加一个三角形,这个三角形是利用两个边框不同颜色产生的楔形制作的 设置盒子的高度和宽度均为0,边框合适的大小,透明颜色,对应边设置高度、颜色 几个变形…

    Linux 2023年6月14日
    0104
  • 如何写好倒计时

    引言 本文讲解倒计时为什么建议使用 setTimeout而不使用 setInterval,倒计时为什么存在误差,以及如何解决。 倒计时器 在前端开发中,倒计时器功能比较常见,比如活…

    Linux 2023年6月7日
    0333
  • QT资料大全

    本文并非原创,摘自: 一去丶二三里 ,感谢大佬的总结 http://blog.csdn.net/liang19890820 推荐另外一个大神的QT总结,受益匪浅啊 https://…

    Linux 2023年6月13日
    074
  • Docker私有仓库搭建

    Docker私有仓库搭建 1、Docker Registry 网上有很多的 Registry服务器都支持第三方用户注册,而后基于用户名去做自己的仓库,但是使用互联网上的 Regis…

    Linux 2023年6月7日
    0152
  • 6.18(反射和注解—>反射机制的作用)

    反射 获取Class对象三种方式第一种方式:类.class第二种方式:对象.getClass()第三种方式:Class.forName 在&#x4E0…

    Linux 2023年6月7日
    0121
  • centos系统和Ubuntu系统命令区别以及常见操作

    一.前言 二.系统环境 三.命令区别 3.1 使用习惯和命令区别 3.2 服务管理的区别 3.3 软件包信息区别 四.Ubuntu系统常见操作 4.1 Ubuntu系统apt和ap…

    Linux 2023年6月7日
    0230
  • 【总结】瞬时高并发(秒杀/活动)Redis方案

    1,Redis 丰富的数据结构(Data Structures) * 字符串(String) – Redis字符串能包含 任意类型的数据 一个字符串类型的值最多能存储 …

    Linux 2023年5月28日
    085
  • 用shell抓取某考试试题

    一、背景 最近公司组织考信息安全,但考试机构没有整理出试题,只给了以下几个在线练习的链接,想着用博客整理下题库题型,奈何这个只能用拍照图片,然后用图片转文字的方式太慢,累死个人了,…

    Linux 2023年6月6日
    0105
  • [20220104]in list 几种写法性能测试.txt

    [20220104]in list 几种写法性能测试.txt –//以前写过几种in list的写法,从来没有测试过这几种方法的性能测试看看. 1.环境:SCOTT@b…

    Linux 2023年6月13日
    059
  • MongoDB安装使用教程

    MongoDB安装使用教程 介绍 MongoDB是一个基于分布式文件存储的数据库,是一个文档数据库,支持的数据结构非常松散,是类似json的bson格式,可以存储比较复杂的数据类型…

    Linux 2023年6月6日
    0101
  • python爬虫_入门

    本来觉得没什么可写的,因为网上这玩意一搜一大把,不过爬虫毕竟是python的一个大亮点,不说说感觉对不起这玩意基础点来说,python2写爬虫重点需要两个模块,urllib和url…

    Linux 2023年6月6日
    090
  • redisobject详解

    typedef struct redisObject { unsigned type:4; unsigned encoding:4; unsigned lru:REDIS_LRU_…

    Linux 2023年5月28日
    0113
  • [云原生]Kubernetes-Pod控制器详解(第6章)

    一、Pod控制器介绍 二、ReplicaSet(RS) 三、Deployment(Deploy) 四、Horizontal Pod Autoscaler(HPA) 五、Daemon…

    Linux 2023年6月13日
    0123
  • neovim环境与vim简单使用

    Github仓库 neovim的配置 这里列出我自己使用的 init.vim,如果插件无法安装,请按照github仓库中给出的解决方法解决(手动clone安装即可)。参考了gith…

    Linux 2023年6月8日
    0102
  • 工程课Linux第一节笔记

    上课笔记 文件系统结构 /根目录 /bin/ 存放系统命令,普通用户与root都可以执行 /etc/ 配置文件保存位置 /lib/ 系统调用的函数库保存位置 /var/ 目录用于存…

    Linux 2023年6月6日
    080
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球