Binary installation of mysql installation

Keywords: Operation & Maintenance MySQL Makefile socket network

Download the tar of mysql binary installation file, and place the GZ package in / usr/local /

Run script file


#!/bin/bash

function Cuser
{
        groupadd -g 27 -o -r mysql
        useradd -M -N -g mysql -o -r -d /usr/local/mysql/data -s /bin/false -c "MySQL Server" -u 27 mysql


}


function file-tar
{
        cd /usr/local/
        FileName=`ls  | grep mysql | sed  '{s/.tar.gz/ /}'`
        echo $FileName
        tar -zxvf /usr/local/mysql*
        ln -s  $FileName    mysql
        export PATH=/usr/local/mysql/bin:$PATH
       
}

function makefile
{
        cd /usr/local/mysql
        mkdir mysql-files
        chown mysql:mysql mysql-files
        chmod 750 mysql-files
     

}

function config
{
        cd /etc
        touch my.cnf
        chown root:root my.cnf
        chmod 644 my.cnf


echo '[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
port=3306
log-error=/usr/local/mysql/data/localhost.localdomain.err
user=mysql
secure_file_priv=/usr/local/mysql/mysql-files
local_infile=OFF
pid-file=/usr/local/mysql/data/mysqld.pid '  > /etc/my.cnf

      
}

function init
{
        cd /usr/local/mysql
        bin/mysqld --defaults-file=/etc/my.cnf  --initialize-insecure
       
}

function Msystemd
{
        cd /usr/lib/systemd/system
        touch mysqld.service
        chmod 644 mysqld.service




echo '[Unit]
Description=MySQL Server
Documentation=man:mysqld(7)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql

Type=forking

PIDFile=/usr/local/mysql/data/mysqld.pid

# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

# Start main service
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --daemonize
--pid-file=/usr/local/mysql/data/mysqld.pid $MYSQLD_OPTS

# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit
LimitNOFILE = 5000

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false' >  mysqld.service


        cd /usr/lib/tmpfiles.d
        touch mysql.conf
        chmod 644 mysql.conf

        echo 'd /usr/local/mysql/data 0750 mysql mysql  -' > mysql.conf

        
}

function startS
{
        systemctl enable mysqld.service
        systemctl start mysqld
        systemctl status mysqld

        
}

function judge
{

        if (( $? == 0 ))
        then
                echo "OK!!!"
        else
                echo "error!!!"
                exit

        fi

}


Cuser
judge

file-tar
judge

makefile
judge
config
judge
init
judge
Msystemd
judge
startS
judge

 

Step 1: create users and groups

groupadd -g 27 -o -r mysql
useradd -M -N -g mysql -o -r -d /usr/local/mysql/data -s /bin/false -c "MySQL Server" -u 27 mysql

Step 2: extract the installation file and create a connection

        cd /usr/local/
        FileName=`ls  | grep mysql | sed  '{s/.tar.gz/ /}'`
        echo $FileName
        tar -zxvf /usr/local/mysql*
        ln -s  $FileName    mysql
        export PATH=/usr/local/mysql/bin:$PATH

Step 3: create import and export folders and set permissions

cd /usr/local/mysql  
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files

Step 4: create a profile, set permissions, and set configuration items

cd /etc
touch my.cnf
chown root:root my.cnf  
chmod 644 my.cnf


echo '[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
port=3306
log-error=/usr/local/mysql/data/localhost.localdomain.err
user=mysql
secure_file_priv=/usr/local/mysql/mysql-files
local_infile=OFF
pid-file=/usr/local/mysql/data/mysqld.pid '  > /etc/my.cnf

The fifth step: initialization, no password

cd /usr/local/mysql
bin/mysqld --defaults-file=/etc/my.cnf --initialize

Step 6: configure systemd control startup script

cd /usr/lib/systemd/system
touch mysqld.service
chmod 644 mysqld.service




echo '[Unit]
Description=MySQL Server
Documentation=man:mysqld(7)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql

Type=forking

PIDFile=/usr/local/mysql/data/mysqld.pid

# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

# Start main service
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --daemonize
--pid-file=/usr/local/mysql/data/mysqld.pid $MYSQLD_OPTS

# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit
LimitNOFILE = 5000

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false' >  mysqld.service

cd /usr/lib/tmpfiles.d
touch mysql.conf
chmod 644 mysql.conf

echo 'd /usr/local/mysql/data 0750 mysql mysql  -' > mysql.conf

Step 7: restart the service and view the status

systemctl enable mysqld.service
systemctl start mysqld
systemctl status mysqld

Posted by Jay87 on Wed, 29 Apr 2020 08:59:44 -0700