Linux Mysql5.7多实例安装2018-04-19

  • 下载 MySQL 5.7 二制包 [ 推荐官方下载 ] 此下载版本大于5.7.5
    wget wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
  • 解压 MySQL 5.7 二进制包到指定目录
    tar zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
  • 解压出来的文件目录中的文件移动到、usr/local/mysql目录下
    mv /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql
  • 在 MySQL 二进制包目录中创建 mysql-files 目录 [MySQL 数据导入/导出数据专放目录]
    mkdir -v /usr/local/mysql/mysql-files
  • 创建多实例数据目录
    mkdir -p /data/mysql/{mysql_3506,mysql_3507,mysql_3508,mysql_3509}
    mkdir /data/mysql/mysql_3506/{data,log,tmp}
    mkdir /data/mysql/mysql_3507/{data,log,tmp}
    mkdir /data/mysql/mysql_3508/{data,log,tmp}
    mkdir /data/mysql/mysql_3509/{data,log,tmp}
  • 修改 MySQL 二进制包目录的所属用户与所属组
    chown root.mysql -R /usr/local/mysql
  • 修改 MySQL 多实例数据目录与 数据导入/导出专放目录的所属用户与所属组
    chown mysql.mysql -R /usr/local/mysql/mysql-
    files//data/mysql/{mysql_3506,mysql_3507,mysql_3508,mysql_3509}
    配置 MySQL 配置文件 /etc/my.cnf
    [mysqld_multi]
    mysqld = /usr/local/src/mysql/bin/mysqld
    mysqladmin = /usr/local/src/mysql/bin/mysqladmin
    log = /tmp/mysql_multi.log

[mysqld3506]
datadir = /data/mysql/mysql_3506/data
socket = /data/mysql/mysql_3506/tmp/mysql.sock1
port = 3506
user = mysql
performance_schema = off
innodb_buffer_pool_size = 32M
bind_address = 0.0.0.0
skip-name-resolve = 0

[mysqld3507]
datadir = /data/mysql/mysql_3507/data
socket = /data/mysql/mysql_3507/tmp/mysql.sock1
port = 3507
user = mysql
performance_schema = off
innodb_buffer_pool_size = 32M
bind_address = 0.0.0.0
skip-name-resolve = 0

[mysqld3508]
datadir = /data/mysql/mysql_3508/data
socket = /data/mysql/mysql_3508/tmp/mysql.sock1
port = 3508
user = mysql
performance_schema = off
innodb_buffer_pool_size = 32M
bind_address = 0.0.0.0
skip-name-resolve = 0

[mysqld3509]
datadir = /data/mysql/mysql_3509/data
socket = /data/mysql/mysql_3509/tmp/mysql.sock1
port = 3509
user = mysql
performance_schema = off
innodb_buffer_pool_size = 32M
bind_address = 0.0.0.0
skip-name-resolve = 0

  • 初始化各个实例 [ 初始化完成后会自带随机密码在输出日志中 ]
    /usr/local/src/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/src/mysql --datadir=/data/mysql/mysql_3506/data
    /usr/local/src/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/src/mysql --datadir=/data/mysql/mysql_3507/data
    /usr/local/src/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/src/mysql --datadir=/data/mysql/mysql_3508/data
    /usr/local/src/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/src/mysql --datadir=/data/mysql/mysql_3509/data
  • 各实例开启 SSL 连接
    /usr/local/src/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/src/mysql --datadir=/data/mysql/mysql_3506/data
    /usr/local/src/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/src/mysql --datadir=/data/mysql/mysql_3507/data
    /usr/local/src/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/src/mysql --datadir=/data/mysql/mysql_3508/data
    /usr/local/src/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/src/mysql --datadir=/data/mysql/mysql_3509/data
  • 复制多实例脚本到服务管理目录下 [ /etc/init.d/ ]
    cp /usr/local/src/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multi
  • 给予脚本可执行权限
    sudo chmod +x /etc/init.d/mysqld_multi
  • 加入service服务管理
    chkconfig --add mysqld_multi
  • 添加环境变量
    vim /etc/profile
     export MYSQL_HOME=/usr/local/mysql

export PATH=${MYSQL_HOME}/bin:$PATH
执行:
source /etc/profile

  • 查看多个实例状态:mysqld_multi report


    image.png
  • 启动各个实例:mysqld_multi start
    此时多实例mysql已经搭建完成
  • 修改密码:
    连接各个实例:
    mysql -S /data/mysql/mysql_3509/tmp/mysql.sock1 -uroot -p
    输入初始化实例的时的密码
    set password for root@'localhost'=password('123456');
    如果此时报错需将实例重启后再次修改。
    GRANT ALL PRIVILEGES ON . TO 'mysql'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
    flush privileges;
    至此搭建完成。

你可能感兴趣的:(Linux Mysql5.7多实例安装2018-04-19)