美文网首页
centos7源码安装mysql5.7.30

centos7源码安装mysql5.7.30

作者: 那年六月六 | 来源:发表于2021-06-18 12:12 被阅读0次

    下载:

    wget https://downloads.mysql.com/archives/get/p/23/file/mysql-boost-5.7.30.tar.gz
    

    安装依赖:

    yum -y install make gcc-c++ cmake bison-devel ncurses-devel
    

    解压:

    tar -zxvf  mysql-boost-5.7.30.tar.gz 
    

    新建目录:

    mkdir -p /usr/local/mysql/data
    

    创建mysql用户和组:

    groupadd mysql
    useradd -r -g mysql mysql    # -r  建立系统帐号,-g<群组>  指定用户所属的群组。
    

    编译、安装:

    cd mysql-5.7.30
    cmake \
    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql    \
    -DMYSQL_DATADIR=/usr/local/mysql/data      \
    -DSYSCONFDIR=/etc                          \
    -DWITH_BOOST=boost                         \
    -DWITH_MYISAM_STORAGE_ENGINE=1             \
    -DWITH_INNOBASE_STORAGE_ENGINE=1           \
    -DWITH_MEMORY_STORAGE_ENGINE=1             \
    -DWITH_READLINE=1                          \
    -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
    -DMYSQL_TCP_PORT=3306                      \
    -DENABLED_LOCAL_INFILE=1                   \
    -DWITH_PARTITION_STORAGE_ENGINE=1          \
    -DEXTRA_CHARSETS=all                       \
    -DDEFAULT_CHARSET=utf8                     \
    -DDEFAULT_COLLATION=utf8_general_ci        \
    make && make install
    

    设置权限:

    chown -R mysql:mysql /usr/local/mysql
    

    初始化MySQL,留意临时密码:

    cd /usr/local/mysql/bin
    ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --initialize
    

    配置启动脚本:

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

    启动MySQL服务、添加到开机启动项

    service mysqld start  或者  /etc/init.d/mysqld start
    chkconfig mysqld on 或者  systemctl enable mysqld.service
    

    查看临时密码:

    cat  /usr/local/mysql/mysql-error.log |grep 'A temporary password'
    

    登录,并修改密码:

    cd /usr/local/mysql/bin
    ./mysql -u root -p
    set password for root@localhost = password('123456');
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
    FLUSH PRIVILEGES;
    

    配置环境变量:

    vim /root/.bash_profile
    PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
    

    立即生效:

    source /root/.bash_profile
    

    /etc/my.cnf 参考:

    [client]
    port=3306
    socket=/usr/local/mysql/mysql.sock
    
    [mysqld]
    datadir=/usr/local/mysql/data
    socket=/usr/local/mysql/mysql.sock
    basedir=/usr/local/mysql
    pid-file=/usr/local/mysql/mysql.pid
    log_error=/usr/local/mysql/mysql-error.log
    slow_query_log=1
    long_query_time=1
    slow_query_log_file=/usr/local/mysql/mysql-slow.log
    
    [mysqldump]
    quick
    max_allowed_packet=16M
    

    相关文章

      网友评论

          本文标题:centos7源码安装mysql5.7.30

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