CentOS 7 下編譯安裝 MySQL-5.7.21

系統環境

操做系統: CentOS Linux release 7.4.1708 (Core)
MySQL版本: MySQL-5.7.21html

  1. 安裝前的準備
  • 編譯安裝MySQL須要一些必備的組件,能夠直接使用yum安裝便可mysql

    yum -y install cmake ncurses-devel gcc-c++
  • 建立 Mysql用戶c++

    useradd mysql
  • 分別給mysql建立程序安裝目錄和數據存儲目錄,這裏將mysql安裝在/opt下,數據存儲在 /data/mysql下sql

    mkdir /opt/mysql-5.7.21
    mkdir /data/mysql/{log,data} -p
  • 到官網下載MySQL的安裝包並解壓, 爲了能使用mysql用戶編譯安裝,下載和解壓要使用mysql用戶,不然解壓完後還須要手動改變源碼的屬主權限,才能使mysql用戶有權限執行編譯安裝vim

    clipboard.png

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

2.開始編譯安裝socket

  • MySQL常見編譯參數ide

    參數 說明
    -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、SRV四、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

    clipboard.png

  • 編譯成功,執行安裝ui

    make install

3.安裝後的工做this

  • /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 便可

    clipboard.png

  • 將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'
相關文章
相關標籤/搜索