1. 下载mysql源码:
    https://dev.mysql.com/downloads/mysql/
  2. 安装依赖:
    yum  -y  install  cmake  gcc  gcc-c++  ncurses  ncurses-devel  libaio-devel  openssl  openssl-devel
  3. 创建文件夹:
    mkdir  mysql_1
    mkdir  mysql_2
  4. 解压:
    tar  -xzf  mysql-boost-5.7.24.tar.gz  -C  mysql_1
    tar  -xzf  mysql-boost-5.7.24.tar.gz  -C  mysql_2
  5. 创建用户:
    useradd  mysql_1  -s  /sbin/nologin  -M
    useradd  mysql_2  -s  /sbin/nologin  -M
  6. 创建文件夹:
    mkdir  -p  /data/mysql/mysql_1/data
    mkdir  -p  /data/mysql/mysql_2/data
  7. 编译安装:
    cd  mysql_1/mysql-5.7.24
    cmake  .  -DCMAKE_INSTALL_PREFIX=/data/mysql/mysql_1  \
    -DMYSQL_DATADIR=/data/mysql/mysql_1/data  \
    -DSYSCONFDIR=/etc  \
    -DMYSQL_TCP_PORT=3307  \
    -DWITH_BOOST=./boost
    make  &&  make  install
    cd  mysql_2/mysql-5.7.24
    cmake  .  -DCMAKE_INSTALL_PREFIX=/data/mysql/mysql_2  \
    -DMYSQL_DATADIR=/data/mysql/mysql_2/data  \
    -DSYSCONFDIR=/etc  \
    -DMYSQL_TCP_PORT=3308  \
    -DWITH_BOOST=./boost
    make  &&  make  install
  8. 改变所属主:
    chown  -R  mysql_1.mysql_1  /data/mysql/mysql_1
    chown  -R  mysql_2.mysql_2  /data/mysql/mysql_2
  9. 创建配置文件:
    vim /etc/mysql_1.cnf
    [mysqld]
    user=mysql_1
    server-id=1
    port=3307
    basedir=/data/mysql/mysql_1
    datadir=/data/mysql/mysql_1/data
    socket=/tmp/mysql_1.sock
    ngram_token_size=2
    log-bin=mysql_1
    slave-skip-errors=all

    vim /etc/mysql_2.cnf

    [mysqld]
    user=mysql_2
    server-id=2
    port=3308
    basedir=/data/mysql/mysql_2
    datadir=/data/mysql/mysql_2/data
    socket=/tmp/mysql_2.sock
    ngram_token_size=2
    log-bin=mysql_2
    slave-skip-errors=all
  10. 初始化:
    /data/mysql/mysql_1/bin/mysqld  --initialize-insecure  --user=mysql_1  --datadir=/data/mysql/mysql_1/data
    /data/mysql/mysql_1/bin/mysql_ssl_rsa_setup --defaults-file=/etc/mysql_1.cnf
    /data/mysql/mysql_2/bin/mysqld  --initialize-insecure  --user=mysql_2  --datadir=/data/mysql/mysql_2/data
    /data/mysql/mysql_2/bin/mysql_ssl_rsa_setup --defaults-file=/etc/mysql_2.cnf
  11. 启动:
    /data/mysql/mysql_1/bin/mysqld_safe  --defaults-file=/etc/mysql_1.cnf  &
    /data/mysql/mysql_2/bin/mysqld_safe  --defaults-file=/etc/mysql_2.cnf  &
  12. 创建远程用户:
    /data/mysql/mysql_1/bin/mysql -S /tmp/mysql_1.sock
    grant all on *.* to 'root'@'%' identified by '123456';
    update mysql.user set Grant_priv='Y' where Host='%';
    delete from mysql.user where Host<>'%' or User<>'root';
    quit;
    /data/mysql/mysql_2/bin/mysql -S /tmp/mysql_2.sock
    grant all on *.* to 'root'@'%' identified by '123456';
    update mysql.user set Grant_priv='Y' where Host='%';
    delete from mysql.user where Host<>'%' or User<>'root';
    quit;
  13. 显示主服务器状态:
    show  master  status;
  14. 切换到主服务器:
    change  master  to
    master_host='172.20.10.12',
    master_port=3308,
    master_user='root',
    master_password='123456',
    master_log_file='mysql_2.000003',
    master_log_pos=154;
    change  master  to
    master_host='172.20.10.12',
    master_port=3307,
    master_user='root',
    master_password='123456',
    master_log_file='mysql_1.000004',
    master_log_pos=154;
  15. 开启从服务器:
    start  slave;
  16. 显示从服务器状态:
    show  slave  status\G
  17. 关闭:
    pkill  mysql

    广告

    给大家推荐几个好用的工具

  18. 时间校验工具
  19. ip查询工具
  20. 二维码生成工具
  21. json格式化工具
  22. 时间缀-时间转换工具