鏈接:MySQL-5.7.26
https://pan.baidu.com/s/1DmDbJzCk95z27WuKVqax1A?pwd=zouq
提取碼:zouq
#!/bin/bash
#要安裝卸載的軟件
yum -y install lrzsz >/dev/null
yum -y remove mysql* >/dev/null
yum -y remove mariadb* >/dev/null
yum -y remove boost-* >/dev/null
yum -y install bzip2 >/dev/null
yum -y install cmake make gcc gcc-c++ ncurses ncurses-devel bison >/dev/null
rpm -ivh mysql-community-5.7.26-1.el7.src.rpm >/dev/null
cd /root/rpmbuild/SOURCES
#解壓
tar -jxvf boost_1_59_0.tar.bz2 -C /root/ >/dev/null
tar -zxvf mysql-5.7.26.tar.gz -C /root/
#檢查用戶和組是否存在
hostname=mysql
if id -u ${hostname} >/dev/null 2>&1;
then
echo “User ${hostname} ok”
else
echo “User ${hostname} error”
groupadd mysql
useradd -M -s /sbin/nologin -r -g mysql mysql
echo “user and group created successfully”
fi
#創(chuàng)建數(shù)據(jù)庫(kù)存放的位置和修改目錄權(quán)限
mkdir -p /data/mysql/{data,log}
chown -R mysql:mysql /data/mysql
#預(yù)編譯
cd /root/mysql-5.7.26
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/data/mysql/data
-DSYSCONFDIR=/etc
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.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
-DDOWNLOAD_BOOST=1
-DWITH_BOOST=/root/boost_1_59_0
make -j $(grep processor /proc/cpuinfo | wc -l)
make install
#修改目錄權(quán)限
chown -R mysql:mysql /usr/local/mysql
#配置備份文件
cat >/etc/my.cnf<<EOF
[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql/data
port=3306
socket=/usr/local/mysql/mysql.sock
symbolic-links=0
character-set-server=utf8
log-error=/data/mysql/log/mysqld.log
pid-file=/usr/local/mysql/mysqld.pid
EOF
#生成啟動(dòng)腳本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
#開(kāi)機(jī)自啟
chkconfig –add mysqld
chkconfig mysqld on
chkconfig –list mysqld
#初始化數(shù)據(jù)庫(kù)
/usr/local/mysql/bin/mysqld –initialize-insecure –user=mysql
–basedir=/usr/local/mysql –datadir=/data/mysql/data
#啟動(dòng)服務(wù)
/etc/init.d/mysqld start
#path路徑軟鏈接
ln -s /usr/local/mysql/bin/* /usr/local/bin/
#修改密碼
mysqladmin -u root password “123456” >/dev/null