MySQL 5.6 source code installation centos 7

MySQL 5.6 source code installation centos 7

#!/bin/bash
##### source code generic linux

sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
getenforce

#hostnamectl set-hostname node$(ip addr |grep global |grep $(route  |grep default |awk '{print $NF}') |head -n1 |awk '{print $2}' |cut -d '/' -f1 |cut -d '.' -f4)

## Install dependencies
yum install -y gcc gcc-c++ ncurses-devel cmake libaio bison autoconf

#Add a user named mysql. # -g: Specify the user group (group) to which the new user belongs # -M: Do not create the root directory # -s: Define the shell it uses, / sbin / nologin means that the user cannot log in to the system.
groupadd mysql
useradd mysql -g mysql -M -s /sbin/nologin

# mysql5.6 Source installation
# 1 Compile and install
 wget http: // cdn.mysql.com/archives/mysql-5.6/mysql-5.6.39.tar.gz -O mysql-5.6.39.tar.gz

tar zxvf mysql-5.6.39.tar.gz && cd  mysql-5.6.39 && cmake ./ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/usr/local/mysql/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci &&  make && make  install


#Parameter Description
# -DCMAKE_INSTALL_PREFIX = / usr / local / mysql \ #installation path
# -DMYSQL_DATADIR = / usr / local / mysql / data \ #Data file storage location
# -DSYSCONFDIR = / etc \ # my.cnf path
# -DWITH_MYISAM_STORAGE_ENGINE = 1                    \ #Support MyIASM engine
# -DWITH_INNOBASE_STORAGE_ENGINE = 1                  \ #Support InnoDB engine
# -DWITH_MEMORY_STORAGE_ENGINE = 1                    \ #Support Memory Engine
# -DWITH_READLINE = 1                                 \ #Shortcut key function (I have not used it)
# -DMYSQL_UNIX_ADDR = / tmp / mysqld.sock \ #Connect to the database socket path
# -DMYSQL_TCP_PORT = 3306                             \ #port
# -DENABLED_LOCAL_INFILE = 1                          \ #Allow data import from local
# -DWITH_PARTITION_STORAGE_ENGINE = 1                 \ #Installation support database partition
# -DEXTRA_CHARSETS = all \ #Install all character sets
# -DDEFAULT_CHARSET = utf8 \ #default character
# -DDEFAULT_COLLATION=utf8_general_ci


\cp ./support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld

echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
source /etc/profile

chown -R mysql:mysql /usr/local/mysql

#Initialize the database
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql


[ $(grep -c 'sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES' /etc/my.cnf) -eq 0 ] && sed -i '/\[mysqld\]/ a sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES' /etc/my.cnf

sed -i 's#^datadir=.*#datadir=/usr/local/mysql/data#g'  /etc/my.cnf
sed -i 's#^socket=.*#socket=/usr/local/mysql/mysql.sock#g'  /etc/my.cnf
sed -i 's#^log-error=.*#datadir=/usr/local/mysql/log/mysql.log#g'  /etc/my.cnf
sed -i 's#^pid-file=.*#pid-file=/usr/local/mysql/mysql.pid#g'  /etc/my.cnf
sed -i 's#^socket=.*#socket=/tmp/mysqld.sock#g'  /etc/my.cnf

#sed -i 's#^socket=.*#socket=/usr/local/mysql/mysql.sock#g'  /etc/my.cnf
#ln -s /usr/local/mysql/mysql.sock /tmp/mysqld.sock
egrep -v '^#|^$' /etc/my.cnf


/etc/init.d/mysqld restart

#systemctl start mysqld 
systemctl enable mysqld 

 

Guess you like

Origin www.cnblogs.com/blog-lhong/p/12692824.html