美文网首页
单版本多实例应用&&多版本多实例应用

单版本多实例应用&&多版本多实例应用

作者: 肥四_F4 | 来源:发表于2020-06-30 14:38 被阅读0次

    错误日志路径:

    [root@db01 ~ 08:54:19]# tail -f /data/3306/data/db01.err
    

    4.6单版本多实例应用
    4.6.1创建相关目录

    [root@db01 ~ 10:39:43]# mkdir -p /data/330{7..9}/data /data/330{7..9}/logs
    

    4.6.2准备配置文件

    cat >/data/3307/my.cnf <<EOF
    [mysqld] 
    user=mysql 
    basedir=/data/app/mysql
    datadir=/data/3307/data 
    server_id=7
    port=3307
    log_bin=/data/3307/logs/mysql-bin
    socket=/tmp/mysql3307.sock
    EOF
    

    4.6.3 授权

    [root@db01 ~]# chown -R mysql. /data/*
    

    4.6.4 初始化数据

    mv /etc/my.cnf /etc/my.cnf.bak
    mysqld --initialize-insecure --user=mysql --basedir=/data/app/mysql --datadir=/data/3307/data 
    mv /etc/my.cnf.bak  /etc/my.cnf
    

    4.6.5启动多实例

    mysqld_safe --defaults-file=/data/3307/my.cnf &
    

    4.6.6使用navicat连接多实例

    #免交互方式创建一个远程用户
    mysql -S /tmp/mysql3307.sock -e "grant all on *.* to root@'10.0.0.%' identified by '123';"
    

    4.6.7 配置多实例systemd

    cat > /etc/systemd/system/mysqld3307.service  <<EOF
    [Unit]
    Description=MySQL Server
    Documentation=man:mysqld(8)
    Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
    After=network.target
    After=syslog.target
    [Install]
    WantedBy=multi-user.target
    [Service]
    User=mysql
    Group=mysql
    ExecStart=/data/app/mysql/bin/mysqld --defaults-file=/data/3307/my.cnf
    LimitNOFILE = 5000
    EOF
    
    [root@db01 ~]# pkill mysqld
    [root@db01 ~]# systemctl start mysqld3307
    [root@db01 ~]# systemctl start mysqld3308
    [root@db01 ~]# systemctl start mysqld3309
    

    4.7 彩蛋:多版本多实例应用
    4.7.1 上传软件、解压、软连接

    tar xf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz 
    tar xf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz 
    ln -s mysql-8.0.18-linux-glibc2.12-x86_64 mysql80
    ln -s mysql-5.6.46-linux-glibc2.12-x86_64 mysql56
    

    4.7.2 创建相关目录

    mkdir -p /data/331{7..8}/data  /data/331{7..8}/logs
    

    4.7.3 准备配置文件

    cat >/data/3317/my.cnf <<EOF
    [mysqld] 
    user=mysql 
    basedir=/data/app/mysql56
    datadir=/data/3317/data 
    server_id=17
    port=3317
    log_bin=/data/3317/logs/mysql-bin
    socket=/tmp/mysql3317.sock
    EOF
    
    cat >/data/3318/my.cnf <<EOF
    [mysqld] 
    user=mysql 
    basedir=/data/app/mysql80
    datadir=/data/3318/data 
    server_id=18
    port=3318
    log_bin=/data/3318/logs/mysql-bin
    socket=/tmp/mysql3318.sock
    EOF
    

    4.7.4 授权

    [root@db01 ~]# chown -R mysql. /data/*
    

    4.7.5 初始化数据

    [root@db01 ~ 11:52:12]# mv /etc/my.cnf /etc/my.cnf.bak
    #注释环境变量
    [root@db01 ~ 11:52:12]# vim /etc/profile
    #export PATH=/data/app/mysql/bin:$PATH
    # 最好重连一个Xshell窗口
    [root@db01 ~]# mysql -V   
    -bash: mysql: command not found  #证明你的环境变量取消了
    
    # 5.6
    [root@db01 ~ 11:52:12]# /data/app/mysql56/scripts/mysql_install_db  --user=mysql --basedir=/data/app/mysql56 --datadir=/data/3317/data 
    # 8.0 
    [root@db01 ~ 11:52:12]# /data/app/mysql80/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/app/mysql80 --datadir=/data/3318/data 
    [root@db01 ~ 11:52:12]# mv /etc/my.cnf.bak /etc/my.cnf
    

    4.7.6 配置systemd管理

    cat > /etc/systemd/system/mysqld3317.service  <<EOF
    [Unit]
    Description=MySQL Server
    Documentation=man:mysqld(8)
    Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
    After=network.target
    After=syslog.target
    [Install]
    WantedBy=multi-user.target
    [Service]
    User=mysql
    Group=mysql
    ExecStart=/data/app/mysql56/bin/mysqld --defaults-file=/data/3317/my.cnf
    LimitNOFILE = 5000
    EOF
    
    
    cat > /etc/systemd/system/mysqld3318.service  <<EOF
    [Unit]
    Description=MySQL Server
    Documentation=man:mysqld(8)
    Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
    After=network.target
    After=syslog.target
    [Install]
    WantedBy=multi-user.target
    [Service]
    User=mysql
    Group=mysql
    ExecStart=/data/app/mysql80/bin/mysqld --defaults-file=/data/3318/my.cnf
    LimitNOFILE = 5000
    EOF
    
    
    [root@db01 ~ 12:34:38]# systemctl start mysqld3317.service
    [root@db01 ~ 12:34:38]# systemctl start mysqld3318.service
    

    4.7.6 连接测试

    [root@db01 app]# /data/app/mysql56/bin/mysql -S /tmp/mysql3317.sock 
    [root@db01 app]# /data/app/mysql80/bin/mysql -S /tmp/mysql3318.sock
    
    

    相关文章

      网友评论

          本文标题:单版本多实例应用&&多版本多实例应用

          本文链接:https://www.haomeiwen.com/subject/xzrtqktx.html