美文网首页我爱编程
MySQL5.7源码编译安装+主从搭建

MySQL5.7源码编译安装+主从搭建

作者: 其实我很dou | 来源:发表于2018-05-03 17:23 被阅读0次

    参考文档:
    https://www.cnblogs.com/galengao/p/5755788.html
    https://blog.csdn.net/beyondlpf/article/details/6996104

    1. 源码包需求 将源码包加入到/usr/local/package下
      源码包下载链接:
      https://pan.baidu.com/s/1bBfG6z9TlErw5y58eGe8Hw 密码:wlld
      cmake-3.5.0.tar.gz
      mysql-5.7.17.tar.gz
      boost_1_59_0.tar.gz
    1. yum安装依赖包
      yum -y install gcc gcc-c++ make cmake ncurses ncurses-devel man ncurses libxml2 libxml2-devel openssl-devel bison bison-devel

    2. 解压boost, 5.7需要boost
      cd /usr/local/package/
      tar zxvf boost_1_59_0.tar.gz
      mv boost_1_59_0 ../

    3. 解压cmake, 并安装
      cd /usr/local/package/
      tar -zxvf cmake-3.5.0.tar.gz && cd cmake-3.5.0/
      ./configure --prefix=/usr/local/cmake
      gmake && make install

    4. 使用cmake编译安装mysql
      cd /usr/local/package/
      tar -zxvf mysql-5.7.17.tar.gz && cd mysql-5.7.17/
      /usr/local/cmake/bin/cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DWITH_BOOST=/usr/local/boost_1_59_0 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
      make && make install

    配置mysql

    cp /etc/my.cnf /etc/my.cnf.bak
    rm -rf /etc/my.cnf

    mysql初始化

    cd /usr/local/mysql
    useradd -r mysql
    chown -R mysql .
    chgrp -R mysql .

    创建数据目录

    mkdir -p /usr/local/mysql/data/
    bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    chown -R root .
    chown -R mysql data/

    复制配置文件

    cp support-files/my-default.cnf /etc/my.cnf

    使用service管理

    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

    将mysql目录加入到环境变量

    vi /etc/profile
    {
    PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
    }
    source /etc/profile

    修改配置文件

    vi /etc/my.cnf
    {
    datadir = /usr/local/mysql/data
    }

    service mysqld start
    ps aux | grep mysqld
    mysql -uroot -p

    修改root密码

    grant all on . to 'root'@'%' identified by 'GfsdX1F8pYL@1s';
    set password = password('GfsdX1F8pYL@1s');

    mysql主从搭建(https://www.jianshu.com/p/b8422c2fa80e)

    主: 192.168.2.22
    从: 192.168.2.23
    1 修改主库和从库配置文件
    主库
    $ vim /etc/my.cnf

    # 启用二进制日志
    log-bin=mysql-bin
    # 服务器唯一ID
    server-id=22
    

    从库:
    $ vim /etc/my.cnf

    # 启用二进制日志,可不配
    log-bin=mysql-bin
    # 服务器唯一ID
    server-id=23
    

    重启

    service mysqld restart;

    在主库建一个专用来备份的 MySQL 账户

    grant replication slave,reload,super on *.* to 'repl'@'%' identified by 'repl';
    flush privileges;
    show master status;
    
    mysql> show master status;
    +------------------+----------+--------------+------------------+-------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
    +------------------+----------+--------------+------------------+-------------------+
    | mysql-bin.000001 |      154 |              |                  |                   |
    +------------------+----------+--------------+------------------+-------------------+
    

    更改从库配置; 指定主库复制地址, 复制用户, 密码, 二进制文件名称以及位置

    change master to master_host='192.168.2.22',master_user='repl',master_password='repl',master_log_file='mysql-bin.000001',master_log_pos=154;

    开启复制

    start slave;

    查看状态

    show slave status\G

    以下两项成功,即完成搭建

    Slave_IO_Running: Connecting
    Slave_SQL_Running: Yes
    

    在主库执行DDL, 查看从库复制状态, 观察有没有报错

    相关文章

      网友评论

        本文标题:MySQL5.7源码编译安装+主从搭建

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