• MySql多实例部署


    mysql多实例部署

    软件安装

    //安装wget工具
    [root@localhost ~]# yum -y install wget
    //下载二进制格式的mysql软件包
    [root@localhost ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
    

    使用xftp把包传进来

    配置用户和组并解压二进制程序至/usr/local下

    //创建mysql用户和组
    [root@localhost ~]# useradd -r -M -s /sbin/nologin mysql   
    [root@localhost ~]# id mysql
    uid=994(mysql) gid=991(mysql) groups=991(mysql)
    
    //解压到usr/local/
    [root@localhost ~]# tar xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/   
    [root@localhost ~]# ls /usr/local/
    bin  games    lib    libexec                              sbin   src
    etc  include  lib64  mysql-5.7.31-linux-glibc2.12-x86_64  share
    
    //映射一个软链接
    [root@localhost ~]# cd /usr/local/
    [root@localhost local]# ln -s mysql-5.7.31-linux-glibc2.12-x86_64 mysql
    
    //改属主属组
    [root@localhost local]# chown -R mysql.mysql mysql*
    [root@localhost local]# ll
    total 0
    drwxr-xr-x. 2 root  root    6 Aug 12  2018 bin
    drwxr-xr-x. 2 root  root    6 Aug 12  2018 etc
    drwxr-xr-x. 2 root  root    6 Aug 12  2018 games
    drwxr-xr-x. 2 root  root    6 Aug 12  2018 include
    drwxr-xr-x. 2 root  root    6 Aug 12  2018 lib
    drwxr-xr-x. 2 root  root    6 Aug 12  2018 lib64
    drwxr-xr-x. 2 root  root    6 Aug 12  2018 libexec
    lrwxrwxrwx. 1 mysql mysql  35 Dec 31 12:04 mysql -> mysql-5.7.31-linux-glibc2.12-x86_64
    drwxr-xr-x. 9 mysql mysql 129 Jun  2  2020 mysql-5.7.31-linux-glibc2.12-x86_64
    drwxr-xr-x. 2 root  root    6 Aug 12  2018 sbin
    drwxr-xr-x. 5 root  root   49 Dec 28 11:58 share
    drwxr-xr-x. 2 root  root    6 Aug 12  2018 src
    [root@localhost local]#
    
    //配置环境变量
    [root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
    [root@localhost ~]# source /etc/profile.d/mysql.sh 
    
    //可以用mysql命令了
    [root@localhost ~]# which mysql
    /usr/local/mysql/bin/mysql
    [root@localhost ~]#
    
    

    创建各实例数据存放的目录

    [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 Dec 31 12:05 3306
    drwxr-xr-x. 2 mysql mysql 6 Dec 31 12:05 3307
    drwxr-xr-x. 2 mysql mysql 6 Dec 31 12:05 3308
    

    安装ncures-compat-libs包

    [root@localhost ~]# yum -y install ncurses-compat-libs
    Updating Subscription Management repositories.
    Unable to read consumer identity
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
    baseos                                              1.1 MB/s | 2.8 kB     00:00    
    appstream                                           1.9 MB/s | 3.2 kB     00:00    
    Dependencies resolved.
    ====================================================================================
     Package                   Architecture Version                  Repository    Size
    ====================================================================================
    Installing:
     ncurses-compat-libs       x86_64       6.1-7.20180224.el8       BaseOS       331 k
    
    Transaction Summary
    ====================================================================================
    Install  1 Package
    
    Total size: 331 k
    Installed size: 1.2 M
    Downloading Packages:
    Running transaction check
    Transaction check succeeded.
    Running transaction test
    Transaction test succeeded.
    Running transaction
      Preparing        :                                                            1/1 
      Installing       : ncurses-compat-libs-6.1-7.20180224.el8.x86_64              1/1 
      Running scriptlet: ncurses-compat-libs-6.1-7.20180224.el8.x86_64              1/1 
      Verifying        : ncurses-compat-libs-6.1-7.20180224.el8.x86_64              1/1 
    Installed products updated.
    
    Installed:
      ncurses-compat-libs-6.1-7.20180224.el8.x86_64                                     
    
    Complete!
    

    初始化各实例

    //初始化3306实例
    [root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data/3306
    2020-12-31T04:06:44.503441Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2020-12-31T04:06:44.983279Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2020-12-31T04:06:45.088814Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2020-12-31T04:06:45.151581Z 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: 989d5871-4b1d-11eb-8ec5-000c29ffb3cc.
    2020-12-31T04:06:45.153172Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2020-12-31T04:06:47.006841Z 0 [Warning] CA certificate ca.pem is self signed.
    2020-12-31T04:06:47.216200Z 1 [Note] A temporary password is generated for root@localhost: W=4XsjdfCa(v
    [root@localhost ~]# echo 'W=4XsjdfCa(v' > 3306 
    
    //初始化3307实例
    [root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data/3307
    2020-12-31T04:08:26.821626Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2020-12-31T04:08:27.177478Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2020-12-31T04:08:27.261184Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2020-12-31T04:08:27.323372Z 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: d5838299-4b1d-11eb-92d3-000c29ffb3cc.
    2020-12-31T04:08:27.326869Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2020-12-31T04:08:28.772149Z 0 [Warning] CA certificate ca.pem is self signed.
    2020-12-31T04:08:29.017978Z 1 [Note] A temporary password is generated for root@localhost: R?t?*ILpU3Tv
    [root@localhost ~]# echo 'R?t?*ILpU3Tv' > 3307
    
    //初始化3308
    [root@localhost ~]# mysqld --initialize --user=mysql --datadir=/opt/data/3308
    2020-12-31T04:09:08.172518Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2020-12-31T04:09:08.574550Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2020-12-31T04:09:08.638532Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2020-12-31T04:09:08.697254Z 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: ee2cad0c-4b1d-11eb-955e-000c29ffb3cc.
    2020-12-31T04:09:08.699639Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2020-12-31T04:09:10.034232Z 0 [Warning] CA certificate ca.pem is self signed.
    2020-12-31T04:09:11.296204Z 1 [Note] A temporary password is generated for root@localhost: =%l(mrl5vwoC
    [root@localhost ~]# echo '=%l(mrl5vwoC' > 3308
    
    // 3306 3307 3308 里面保存的是密码,但是是临时密码
    [root@localhost ~]# ls
    3306  3307  3308  anaconda-ks.cfg  mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
    [root@localhost ~]# 
    
    

    安装perl

    [root@localhost ~]# yum -y install perl
    

    配置配置文件/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
    

    启动各实例

    [root@localhost ~]# mysqld_multi start 3306
    [root@localhost ~]# mysqld_multi start 3307
    [root@localhost ~]# mysqld_multi start 3308
    [root@localhost ~]# ss -antl  //3306 3307 3308端口已经起来了
    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          80                         *:3307                    *:*       
    LISTEN    0          80                         *:3308                    *:*       
    LISTEN    0          128                     [::]:22                   [::]:*       
    [root@localhost ~]# 
    

    初始化密码

    注意: 这里-S是指定文件位置

    //设置3306的密码
    [root@localhost ~]# cat 3306
    W=4XsjdfCa(v
    [root@localhost ~]# mysql -uroot -p'W=4XsjdfCa(v' -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.31
    
    Copyright (c) 2000, 2020, 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('123456');
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    mysql> quit
    Bye
    
    //设置3307的密码
    [root@localhost ~]# cat 3307
    R?t?*ILpU3Tv
    [root@localhost ~]# mysql -uroot -p'R?t?*ILpU3Tv' -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.31
    
    Copyright (c) 2000, 2020, 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('123456');
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    mysql> quit
    Bye
    
    //设置3308的密码
    [root@localhost ~]# cat 3308
    =%l(mrl5vwoC
    [root@localhost ~]# mysql -uroot -p'=%l(mrl5vwoC' -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.31
    
    Copyright (c) 2000, 2020, 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('123456');
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    mysql> quit
    Bye
    

    测试登录

    //登录3306实例
    [root@localhost ~]# mysql -uroot -p123456 -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 5
    Server version: 5.7.31 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2020, 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> quit
    Bye
    
    //登录3307实例
    [root@localhost ~]# mysql -uroot -p123456 -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 3
    Server version: 5.7.31 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2020, 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> quit
    Bye
    
    //登录3308实例
    [root@localhost ~]# mysql -uroot -p123456 -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 3
    Server version: 5.7.31 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2020, 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> quit
    Bye
    

    验证成功,以上就是mysql多实例部署

  • 相关阅读:
    Hbase的数据目录更换后server is not running yet报错
    挂载新加4T硬盘到home目录
    Hadoop(二)--Hadoop运行模式
    Hadoop(一)--Hadoop框架介绍
    KubeSphere(四)--Devops工程pipeline
    KubeSphere(三)--示例:安装wordpress到k8s
    KubeSphere(二)--多租户管理权限控制
    KubeSphere(一)--基于k8s安装KubeSphere
    com.alibaba.fastjson.JSON.toJSONString使用时值为NULL的属性被忽略的问题
    数据库命令-实战
  • 原文地址:https://www.cnblogs.com/leixixi/p/14215898.html
Copyright © 2020-2023  润新知