• 當前位置:首頁 > IT技術 > 系統服務 > 正文

    Linux第十周
    2022-03-06 18:01:52

    2、通過編譯、二進制安裝MySQL5.7

    ?二進制安裝MYSQL5.7?

    #創建目錄并進入
    mkdir /server/
    cd /server
    #上傳剛下載的5.7的二進制包
    [root@centos8-2 server]# ll
    total 650940
    -rw-r--r-- 1 root root 666559924 Jan 25 10:18 mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
    #解包
    tar xf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
    #做軟鏈接
    [root@centos8-2 server]# ln -s mysql-5.7.36-linux-glibc2.12-x86_64 /server/mysql
    [root@centos8-2 server]# ll
    total 650940
    lrwxrwxrwx 1 root root 35 Jan 26 10:49 mysql -> mysql-5.7.36-linux-glibc2.12-x86_64
    drwxr-xr-x 9 root root 129 Jan 26 10:48 mysql-5.7.36-linux-glibc2.12-x86_64
    -rw-r--r-- 1 root root 666559924 Jan 25 10:18 mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
    #創建用戶
    groupadd mysql
    useradd -r -g mysql -s /bin/false mysql
    #設置環境變量并執行
    [root@centos8-2 server]# vim /etc/profile.d/mysql.sh
    export PATH=/server/mysql/bin:$PATH
    source /etc/profile
    #授權和創數據目錄
    chown -R mysql.mysql /server/*
    mkdir /data/mysql/data -p
    chown -R mysql.mysql /data
    #安裝依賴
    [root@centos8-2 server]# yum install -y libaio-devel
    初始化
    # 5.6 版本 初始化命令 /application/mysql/scripts/mysql_install_db
    # 5.7跳過密碼初始化
    [root@centos8-2 server]# mysqld --initialize-insecure --user=mysql --basedir=/server/mysql --datadir=/data/mysql/data
    2022-01-26T02:57:10.811504Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2022-01-26T02:57:10.938434Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2022-01-26T02:57:10.960969Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2022-01-26T02:57:11.016304Z 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: a82719f7-7e53-11ec-8563-000c29ffc567.
    2022-01-26T02:57:11.018223Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2022-01-26T02:57:11.872502Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
    2022-01-26T02:57:11.872527Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
    2022-01-26T02:57:11.872974Z 0 [Warning] CA certificate ca.pem is self signed.
    2022-01-26T02:57:12.288739Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
    #復制啟動腳本
    [root@centos8-2 server]# cp /server/mysql/support-files/mysql.server /etc/init.d/mysqld
    #配置文件
    [root@centos8-2 server]# vim /etc/my.cnf
    er=mysql
    er=mysql
    [mysqld]
    user=mysql
    basedir=/server/mysql
    datadir=/data/mysql/data
    server_id=2
    port=3306
    log_bin = mysql-bin
    sync_binlog = 1
    binlog_ignore_db = information_schema
    binlog_ignore_db = performation_schema
    binlog_ignore_db = sys
    character-set-server = utf8mb4
    collation-server = utf8mb4_unicode_ci
    [mysql]
    port = 3306
    default-character-set = utf8
    [client]
    port = 3306
    default-character-set = utf8
    #啟動服務
    [root@centos8-2 server]# /etc/init.d/mysqld start
    Starting MySQL.Logging to '/data/mysql/data/centos8-2.err'.
    [ OK ]
    #登錄數據庫
    [root@centos8-2 server]# mysql -uroot
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 3
    Server version: 5.7.36-log MySQL Community Server (GPL)

    Copyright (c) 2000, 2021, Oracle and/or its affiliates.

    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.

    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    mysql>

    ?編譯安裝MYSQL5.7?

    #安裝相關依賴包
    yum install -y gcc gcc-c++ cmake ncurses ncurses-devel bison wget openssl-devel.x86_64
    #創建用戶和組
    groupadd mysql
    useradd mysql -s /sbin/nologin -M -g mysql
    #下載下載的包導入centos
    [root@centos8-2 local]# cd /usr/local/mysql/
    [root@centos8-2 mysql]# ls
    mysql-5.7.36.tar.gz
    [root@centos8-2 mysql]# tar xf mysql-boost-5.7.29.tar.gz
    #配置相關參數
    [root@centos8-2 mysql]# cd mysql-5.7.36
    [root@centos8-2 mysql]# cmake -DCMAKE_INSTALL_PREFIX=/application/mysql -DMYSQL_DATADIR=/application/mysql/data -DMYSQL_UNIX_ADDR=/application/mysql/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost
    #報錯沒有安裝boostC++庫
    #解決方法方法
    #在cmake命令參數最后增加-DDOWNLOAD_BOOST=1
    #重新運行cmake命令報錯
    #報錯Could not find rpcgen
    #解決方案,訪問github搜索rpcsvc
    #選擇thkukuk-rpcsvc下載源碼
    #導入centos
    [root@centos8-2 ~]# tar -xvf rpcsvc-proto-1.4.1.tar
    [root@centos8-2 ~]# cd rpcsvc-proto-1.4.1
    [root@centos8-2 ~]# ./configure
    [root@centos8-2 ~]# make
    [root@centos8-2 ~]# make install
    #安裝完成后運行
    [root@centos8-2 ~]# cmake -DCMAKE_INSTALL_PREFIX=/application/mysql -DMYSQL_DATADIR=/application/mysql/data -DMYSQL_UNIX_ADDR=/application/mysql/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost
    #編譯安裝(-j指定多核運行編譯)
    #虛擬機設置中調高CPU加快速度
    [root@ctos3 mysql-5.7.29]# make -j 8 && make install
    #安裝到82%報錯,類似于fatal error:Killed signal terminated program cc1plus
    #原因為內存不足
    #解決方法:調大虛擬機內存,發現只能調到3G,實際16G內存,此時需要關閉虛擬機
    #在進行設置,設置為8G后,問題解決
    #設置完成后再次運行
    [root@ctos3 mysql-5.7.29]# make -j 8 && make install
    #創建數據目錄和修改權限
    mkdir /application/mysql/data #存放數據目錄
    mkdir /application/mysql/tmp #存放sock目錄
    chown -R mysql.mysql /application/mysql/
    #配置/etc/my.cnf文件
    cat /etc/my.cnf
    [mysqld]
    port = 3306
    socket = /application/mysql/tmp/mysql.sock
    user = mysql
    basedir = /application/mysql
    datadir = /application/mysql/data
    pid-file = /application/mysql/data/mysql.pid
    sql_mode='ONLY_FULL_GROUP_BY'
    log_error = /application/mysql/mysql-error.log
    !includedir /etc/my.cnf.d

    [client]
    port = 3306
    socket = /application/mysql/tmp/mysql.sock
    #初始化數據庫
    /application/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/application/mysql/dat
    #報錯[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defau
    #在my.cnf文件的[mysqld]中增加explicit_defaults_for_timestamp=true
    #設置環境變量
    [root@centos8-2 support-files]# echo 'export PATH=/application/mysql/bin:$PATH' >> /etc/profile
    [root@centos8-2 support-files]# source /etc/profile
    [root@centos8-2 support-files]# tail -1 /etc/profile
    export PATH=/application/mysql/bin:$PATH
    #生成啟動腳本
    [root@centos8-2 ~]# cd /application/mysql/support-files/
    [root@centos8-2 support-files]# ls
    magic mysqld_multi.server mysql-log-rotate mysql.server
    [root@centos8-2 support-files]# cp mysql.server /etc/init.d/mysqld
    #登錄數據庫
    [root@centos8-2 support-files]# mysql -uroot -p
    Enter password:
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 3
    Server version: 5.7.36 Source distribution

    Copyright (c) 2000, 2021, Oracle and/or its affiliates.

    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.

    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

    mysql>

    3、二進制安裝mariadb10.4

    cd /usr/local
    tar xf mariadb-10.5.8-linux-systemd-x86_64.tar.gz
    ln -s mariadb-10.5.8-linux-systemd-x86_64 mysql
    cd mysql/
    useradd -r -s/sbin/nologin mysql
    chown -R mysql.mysql /usr/local/mysql/
    echo 'PATH=/usr/local/mysql/bin/:$PATH' >/etc/profile.d/mysql.sh
    . /etc/profile.d/mysql.sh
    ./scripts/mysql_install_db --datadir=/data/mysql
    #報錯./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
    yum install -y libaio
    chown -R mysql.mysql /data/mysql
    cp support-files/systemd/mariadb.service /usr/lib/systemd/system/
    vim /etc/my.cnf
    [mysqld]
    datadir=/data/mysql
    socket=/data/mysql/mysql.sock
    mkdir /etc/my.cnf.d
    vim /etc/my.cnf.d/mysql-clients.cnf
    [mysql]
    socket=/data/mysql/mysql.sock
    systemctl start mariadb
    ln -s /data/mysql/mysql.sock /tmp/
    mysql_secure_installation
    rm -f /tmp/mysql.sock


    本文摘自 :https://blog.51cto.com/u

    開通會員,享受整站包年服務
    国产呦精品一区二区三区网站|久久www免费人咸|精品无码人妻一区二区|久99久热只有精品国产15|中文字幕亚洲无线码