通用(use)二進制包安裝mysql 5.7.36

2022-03-31 欄目:技術知識

安裝步驟

    • 清除環境(mariadb)

    [root@labln1 ~]# rpm -qa | grep mariadb
    mariadb-libs-5.5.68-1.el7.x86_64
    [root@labln1 ~]# yum remove mariadb-libs-5.5.68-1.el7.x86_64 -y
    • 創建用(use)戶和(and)組

    [root@labln1 ~]# useradd mysql -s /sbin/nologin
    [root@labln1 ~]# getent passwd | grep mysql
    mysql:x:1000:1000::/home/mysql:/sbin/nologin
    • 創建相關目錄(數據)

    [root@labln1 local]# mkdir -p /data/mysql
    • 設置權限

    [root@labln1 local]# chown -R mysql.mysql /usr/local/mysql/
    [root@labln1 local]# chown -R mysql.mysql /data/mysql/
    • 上(superior)傳并解壓mysql二進制文件

    [root@labln1 local]# wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.36-el7-x86_64.tar.gz
    [root@labln1 local]tar xvzf mysql-5.7.36-el7-x86_64.tar.gz
    [root@labln1 local]# ln -s mysql-5.7.36-el7-x86_64.tar.gz mysql
    [root@labln1 local]# chown -R mysql.mysql mysql
    • 設置環境變量

    [root@labln1 mysql]# echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
    [root@labln1 mysql]# source /etc/pro
    • 初始化系統庫表

    [root@labln1 data]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
    2022-01-06T16:24:41.204827Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.18-el7-x86_64/bin/mysqld (mysqld 8.0.18) initializing of server in progress as process 2431
    2022-01-06T16:24:43.535636Z 5 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
    • 配置文件設定

    [root@labln1 mysql]# vim /etc/my.cfg
     1 [mysqld]
     2 user=mysql
     3 basedir=/usr/local/mysql
     4 datadir=/data/mysql
     5 lc_messages_dir=/usr/local/mysql/share
     6 server_id=6
     7 port=3306
     8 socket=/tmp/mysql.sock
     9 #log_bin=/data/mysqldb/mysql-bin                    
    10 log-error=/data/mysql/db.error.log
    11 pid-file=/data/mysql/mysql.pid
    12 [mysql]
    13 socket=/tmp/mysql.sock
    • 配置啓動方法一(one):

    [root@labln1 support-files]# cp mysql.server /etc/init.d/mysqld
    [root@labln1 support-files]# vim /etc/init.d/mysqld
    46 basedir=/usr/local/mysql
    47 datadir=/data/mysql
    [root@labln1 support-files]# chkconfig --add mysqld
    [root@labln1 support-files]# chkconfig --level 23 mysqld on
    [root@labln1 ~]# lsof -i:3306
    [root@labln1 ~]# systemctl start mysqld.service
    [root@labln1 ~]# systemctl status mysqld.service
    ● mysqld.service - LSB: start and stop MySQL
      Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
      Active: active (running) since Fri 2022-01-07 01:16:42 CST; 11s ago
        Docs: man:systemd-sysv-generator(8)
    Process: 2520 ExecStop=/etc/rc.d/init.d/mysqld stop (code=exited, status=0/SUCCESS)
    Process: 2682 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
      CGroup: /system.slice/mysqld.service
              ├─2687 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysqldb --pid-file=/data/mysqldb...
              └─2774 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysqldb --plugin-d...

    Jan 07 01:16:41 labln1 systemd[1]: Starting LSB: start and stop MySQL...
    Jan 07 01:16:42 labln1 mysqld[2682]: Starting MySQL. SUCCESS!
    Jan 07 01:16:42 labln1 systemd[1]: Started LSB: start and stop MySQL.
    [root@labln1 ~]# lsof -i:3306
    COMMAND PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    mysqld  2774 mysql   29u IPv6  28483     0t0 TCP *:mysql (LISTEN)
    • 啓動配置方法二:

    [root@mysql /]# cd /etc/systemd/system/
    [root@mysql system]# vim mysqld.service
    [Unit]
    Description=MySQL Server
    Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
    After=network.target
    After=syslog.target

    [Service]
    User=mysql
    Group=mysql                                                                                                                                                                
    ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cfg
    Restart=on-failure
    RestartPreventExitStatus=1
    TimeoutSec=0
    PrivateTmp=false
    LimitNOFILE=65535
    LimitNPROC=65535

    [Install]
    WantedBy=multi-user.target
    [root@mysql system]# chown mysql.msyql mysqld.service
    [root@mysql system]# systemctl start mysqld.service
    [root@mysql system]# systemctl enable mysqld.service
    Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /etc/systemd/system/mysqld.service.

啓動方式