通用二进制包安装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
    • 创建用户和组

    [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/
    • 上传并解压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
    • 配置启动方法一:

    [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.

启动方式