CentOS 7 下编译安装 MySQL-5.7.21

前端之家收集整理的这篇文章主要介绍了CentOS 7 下编译安装 MySQL-5.7.21前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

系统环境

操作系统: CentOS Linux release 7.4.1708 (Core)
MysqL版本: MysqL-5.7.21

  1. 安装前的准备
  • 编译安装MysqL需要一些必备的组件,可以直接使用yum安装即可

    yum -y install cmake ncurses-devel gcc-c++
  • 创建 MysqL用户

    useradd MysqL
  • 分别给MysqL创建程序安装目录和数据存储目录,这里将MysqL安装在/opt下,数据存储在 /data/MysqL

    mkdir /opt/MysqL-5.7.21
    mkdir /data/MysqL/{log,data} -p
  • 到官网下载MysqL的安装包并解压,为了能使用MysqL用户编译安装,下载和解压要使用MysqL用户,否则解压完后还需要手动改变源码的属主权限,才能使MysqL用户有权限执行编译安装

    wget https://cdn.MysqL.com//Downloads/MysqL-5.7/MysqL-5.7.21.tar.gz
    tar xf MysqL-5.7.21.tar.gz

2.开始编译安装

  • MysqL常见编译参数

    参数 说明
    -DCMAKE_INSTALL_PREFIX=dir_name 基础的文件夹,对应MysqLd的--basedir参数
    -DINSTALL_BINDIR=dir_name bin目录位置
    -DINSTALL_DOCDIR=dir_name 文档目录位置
    -DINSTALL_DOCREADMEDIR=dir_name Readme文件位置
    -DINSTALL_INCLUDEDIR=dir_name Include目录位置
    -DINSTALL_LAYOUT=name 布局选项,包括Standalone、RPM、SRV4、DEB
    -DMysqL_DATADIR=dir_name 数据存放目录
    -DSYSCONFDIR=dir_name 默认配置my.cnf目录
  • 进入MysqL目录,开始编译

    cmake -DCMAKE_INSTALL_PREFIX=/opt/MysqL-5.7.21 -DMysqL_DATADIR=/data/MysqL -DSYSCONFDIR=/opt/MysqL-5.7.21/conf -DMysqL_UNIX_ADDR=/tmp/MysqL.sock -DDEFAULT_CHARSET=utf8 -DWITH_SSL=yes -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/opt/MysqL-5.7.21

  • 编译成功,执行安装

    make install

3.安装后的工作

  • /opt/MysqL-5.7.21目录下创建 conf目录,并将源码包中的MysqL默认配制文件拷贝至其中

    mkdir /opt/MysqL-5.7.21/conf/
    cp  packaging/rpm-common/my.cnf  /opt/MysqL-5.7.21/conf/
  • 初始化MysqL

    ./bin/MysqLd --defaults-file=/opt/MysqL-5.7.21/conf/my.cnf --datadir=/data/MysqL --initialize-insecure --collation-server=utf8_general_ci --explicit_defaults_for_timestamp=true
    2018-02-12T06:48:25.794971Z 0 [Warning] InnoDB: New log files created,LSN=45790
    2018-02-12T06:48:25.858793Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2018-02-12T06:48:25.915154Z 0 [Warning] No existing UUID has been found,so we assume that this is the first time that this server has been started. Generating a new UUID: b9bda646-0fc0-11e8-b0a0-5254005cdf47.
    2018-02-12T06:48:25.916131Z 0 [Warning] Gtid table is not ready to be used. Table 'MysqL.gtid_executed' cannot be opened.
    2018-02-12T06:48:26.297824Z 0 [Warning] CA certificate ca.pem is self signed.
    2018-02-12T06:48:26.420848Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
  • 修改MysqL配制并创建 MysqL log目录

    # For advice on how to change settings please see
    # http://dev.MysqL.com/doc/refman/5.7/en/server-configuration-defaults.html
    
    [MysqLd]
    #
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MysqL. Start at 70% of total RAM for dedicated server,else 10%.
    # innodb_buffer_pool_size = 128M
    #
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    #
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed,experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
    datadir=/data/MysqL
    socket=/tmp/MysqL.sock
    
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    
    log-error=/data/MysqL/log/MysqLd.log
    pid-file=/data/MysqL/MysqLd.pid
    mkdir /data/MysqL/log
  • 添加MysqL系统启动脚本

    cp -p support-files/MysqL.server /etc/init.d/MysqLd
    /etc/init.d/MysqLd start

    报错:

    Starting MysqL. ERROR! The server quit without updating PID file (/data/MysqL/MysqLd.pid).

    查看错误日志

    tail /data/MysqL/log/MysqL
    
    ----------
    
    2018-02-12T06:58:48.615325Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2018-02-12T06:58:48.615416Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
    2018-02-12T06:58:48.615453Z 0 [Note] /opt/MysqL-5.7.21/bin/MysqLd (MysqLd 5.7.21) starting as process 24900 ...
    2018-02-12T06:58:48.617334Z 0 [ERROR] COLLATION 'latin1_swedish_ci' is not valid for CHARACTER SET 'utf8'
    2018-02-12T06:58:48.617368Z 0 [ERROR] Aborting
    
    2018-02-12T06:58:48.617389Z 0 [Note] Binlog end
    2018-02-12T06:58:48.617574Z 0 [Note] /opt/MysqL-5.7.21/bin/MysqLd: Shutdown complete
    
    2018-02-12T06:58:48.625393Z MysqLd_safe MysqLd from pid file /data/MysqL/MysqLd.pid ended

    修改 MysqL启动脚本,在启动参数中加上 --collation-server=utf8_general_ci 即可

  • MysqL添加进系统环境变量中

    vim /etc/profile.d/MysqL.sh
    
    ----------
    export PATH=$PATH:/opt/MysqL-5.7.21/bin
    
    
    ----------
    source /etc/profile.d/MysqL.sh
  • MysqL的root用户设置密码

    MysqLadmin -u root password '123456'

猜你在找的CentOS相关文章