#!/bin/bash
read -p "提示:需要在线源安装某些软件包"
read -p "准备安装mysql及python自动补全功能,所需安装包是否已准备好(yes/no):" a
if [ $a = no ];then
echo "快去准备安装包吧"
else
echo "开始安装"
read -p "你的安装包目录路径是:" b
echo "数据库用户名默认为 mysql "
read -p "设定数据库用户密码是:" c
read -p "最多支持几核同时进行编译安装:" d
systemctl stop firewalld
setenforce 0
#mysql
yum -y install \
ncurses \
ncurses-devel \
bison \
cmake &> /dev/null
tar zxvf $b/mysql-5.7.17.tar.gz -C $b
tar zxvf $b/boost_1_59_0.tar.gz -C $b
mv $b/boost_1_59_0 /usr/local/boost
useradd -M -s /sbin/nologin mysql
cd $b/mysql-5.7.17
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=/usr/local/boost \
-DWITH_SYSTEMD=1 &> /dev/null
make -j$d && make install
echo "[client]
port = 3306
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
auto-rehash
[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES" > /etc/my.cnf
chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf
echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
source /etc/profile
cd /usr/local/mysql/bin/
./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &> /dev/null
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld.service
systemctl restart mysqld.service
yum install -y expect &> /dev/null
gaimima(){
/usr/bin/expect << EOF
spawn mysqladmin -u root -p password "$c"
expect "Enter password" {send "\r"}
expect eof
EOF
}
gaimima
shouquan() {
/usr/bin/expect <<EOF
spawn mysql -u root -p
expect "Enter password:" {send "$c\r"}
expect "mysql>" {send "grant all privileges on *.* to 'root'@'%' identified by '$c';\r"}
expect "mysql>" {send "quit\r"}
expect eof
EOF
}
shouquan
echo "mysql 安装完毕"
#补全
yum -y install epel-release
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel gcc
mkdir ~/.pip
cat > ~/.pip/pip.conf <<EOF
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
EOF
yum -y install libffi-devel zlib* python-devel openssl-devel &> /dev/null
tar -zxvf $b/Python-3.9.0.tgz -C $b
ln -s /usr/local/python/bin/python3 /usr/bin/
cd $b/Python-3.9.0/
./configure --prefix=/usr/local/python --with-ssl &> /dev/null
make -j$d && make install &> /dev/null
echo 'export PATH=/usr/local/python/bin:$PATH' >> /etc/profile
source /etc/profile
pip3 install mycli
fi