linux下自动安装mysql 5.7.2 数据库

1、下载脚本wget -c http://iskyinfo.gicp.net:5200/linux-mysql/mysqlinstall.sh
2、执行脚本:sh mysqlinstall.sh

3、脚本内容

#!/bin/bash
#############可修改密码、端口、密码安全级别开关#####################
mysqlpasswd=123456
mysqlport=3306
datadir=/data/mysqldata
logerrordir=/data/mysqllog
##################################
starttime=date +'%Y-%m-%d %H:%M:%S'
echo “=开始安装mysql5.7.20:"$starttime""
echo "=卸载系统自带的Mysql
======”
pkill -9 mysql
/bin/rpm -e $(/bin/rpm -qa | grep mysql|xargs) --nodeps
/bin/rpm -e KaTeX parse error: Expected 'EOF', got '#' at position 69: …-f /etc/my.cnf #̲新建mysql用户和组 /us…datadir" ];
then
mkdir -p $datadir && chmod 755 -R $datadir/
chown mysql:mysql $datadir/
mkdir -p $logerrordir && chmod 755 -R $logerrordir
chown mysql:mysql $logerrordir/
else
rm -rf /data/mysqldata_bak
mkdir -p /data/mysqldata_bak
mv $datadir/** /data/mysqldata_bak
mkdir -p $logerrordir && chmod 755 -R $logerrordir
chown mysql:mysql $logerrordir/
fi
echo “=安装基础环境包=============”
/usr/bin/yum -y install wget gcc-c++ cmake bison-devel libaio
#离线下载安装包
#yum install --downloadonly --downloaddir=./ wget
mkdir -p /opt/linux-basic
cd /opt/linux-basic && rm -rf /opt/linux-basic/.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/bison-devel-3.0.4-2.el7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/cmake-2.8.12.2-2.el7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/cpp-4.8.5-44.el7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/gcc-4.8.5-44.el7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/gcc-c+±4.8.5-44.el7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/glibc-2.17-324.el7_9.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/glibc-common-2.17-324.el7_9.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/glibc-devel-2.17-324.el7_9.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/glibc-headers-2.17-324.el7_9.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/kernel-headers-3.10.0-1160.31.1.el7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/libarchive-3.1.2-14.el7_7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/libgcc-4.8.5-44.el7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/libgomp-4.8.5-44.el7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/libmpc-1.0.1-3.el7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/libstdc+±4.8.5-44.el7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/libstdc+±devel-4.8.5-44.el7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/mpfr-3.1.1-4.el7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-basic/wget-1.14-18.el7_6.1.x86_64.rpm
echo “=安装基础包====”
rpm -ivh bison-devel-3.0.4-2.el7.x86_64.rpm
rpm -ivh kernel-headers-3.10.0-1160.31.1.el7.x86_64.rpm
rpm -ivh libarchive-3.1.2-14.el7_7.x86_64.rpm
rpm -ivh mpfr-3.1.1-4.el7.x86_64.rpm
rpm -ivh wget-1.14-18.el7_6.1.x86_64.rpm
rpm -ivh cmake-2.8.12.2-2.el7.x86_64.rpm
rpm -Uvh libgcc-4.8.5-44.el7.x86_64.rpm
rpm -Uvh libgomp-4.8.5-44.el7.x86_64.rpm
rpm -ivh libmpc-1.0.1-3.el7.x86_64.rpm
rpm -Uvh libstdc+±4.8.5-44.el7.x86_64.rpm
rpm -ivh cpp-4.8.5-44.el7.x86_64.rpm
rpm -Uvh glibc-2.17-324.el7_9.x86_64.rpm glibc-common-2.17-324.el7_9.x86_64.rpm
rpm -ivh glibc-headers-2.17-324.el7_9.x86_64.rpm
rpm -ivh glibc-devel-2.17-324.el7_9.x86_64.rpm
rpm -ivh libstdc+±devel-4.8.5-44.el7.x86_64.rpm
rpm -ivh gcc-4.8.5-44.el7.x86_64.rpm
rpm -ivh gcc-c+±4.8.5-44.el7.x86_64.rpm
echo “=下载MySQL安装包====”
mkdir -p /opt/linux-mysql
cd /opt/linux-mysql && rm -rf /usr/local/mysql && rm -rf /opt/linux-mysql/
.rpm && rm -rf /var/lib/mysql
wget -c http://iskyinfo.gicp.net:5200/linux-mysql/mysql-community-client-5.7.20-1.el7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-mysql/mysql-community-common-5.7.20-1.el7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-mysql/mysql-community-libs-5.7.20-1.el7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-mysql/mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm
wget -c http://iskyinfo.gicp.net:5200/linux-mysql/mysql-community-server-5.7.20-1.el7.x86_64.rpm
echo “安装MySQL==”
rpm -ivh mysql-community-common-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
echo “配置my.cnf=”
cat > /etc/my.cnf << EOF
[root@ecs-dd3c-0218609 oauth2-service]# vi /etc/my.cnf

For advice on how to change settings please see

http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]

Remove leading # and set to the amount of RAM for the most important data

cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

innodb_buffer_pool_size = 128M

Remove leading # to turn on a very important data integrity option: logging

changes to the binary log between backups.

log_bin

Remove leading # to set options mainly useful for reporting servers.

The server defaults are faster for transactions and fast SELECTs.

Adjust sizes as needed, experiment to find the optimal values.

join_buffer_size = 128M

sort_buffer_size = 2M

read_rnd_buffer_size = 2M

#datadir=/var/lib/mysql
datadir= d a t a d i r s o c k e t = / v a r / l i b / m y s q l / m y s q l . s o c k p o r t = datadir socket=/var/lib/mysql/mysql.sock port= datadirsocket=/var/lib/mysql/mysql.sockport=mysqlport

Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0
#log-error=/var/log/mysqld.log
log-error=/data/mysqllog/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
lower_case_table_names=1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
max_allowed_packet = 1024M
plugin-load-add=validate_password.so
validate-password=FORCE_PLUS_PERMANENT
max_connections=1000
#validate_password=KaTeX parse error: Expected 'EOF', got '#' at position 323: …=============" #̲设置mysql登陆密码,密码为mysqlpasswd
mysql -h127.0.0.1 -uroot -P m y s q l p o r t − p 1 − e " u s e m y s q l ; u p d a t e u s e r s e t a u t h e n t i c a t i o n s t r i n g = p a s s w o r d ( ′ mysqlport -p1 -e "use mysql;update user set authentication_string=password(' mysqlportp1e"usemysql;updateusersetauthenticationstring=password(mysqlpasswd’) where user=‘root’;"
sed -i ‘/skip-grant-tables/d’ /etc/my.cnf
systemctl restart mysqld.service
mysql -h127.0.0.1 -uroot -P m y s q l p o r t − p mysqlport -p mysqlportpmysqlpasswd -e “SET PASSWORD FOR ‘root’@‘localhost’ = PASSWORD(‘ m y s q l p a s s w d ′ ) ; " − b − − c o n n e c t − e x p i r e d − p a s s w o r d m y s q l − h 127.0.0.1 − u r o o t − P mysqlpasswd');" -b --connect-expired-password mysql -h127.0.0.1 -uroot -P mysqlpasswd);"bconnectexpiredpasswordmysqlh127.0.0.1urootPmysqlport -p m y s q l p a s s w d − e " S E T P A S S W O R D F O R ′ r o o t ′ @ ′ l o c a l h o s t ′ = P A S S W O R D ( ′ mysqlpasswd -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD(' mysqlpasswde"SETPASSWORDFORroot@localhost=PASSWORD(mysqlpasswd’);” -b --connect-expired-password
mysql -h127.0.0.1 -uroot -P m y s q l p o r t − p mysqlport -p mysqlportpmysqlpasswd -e “flush PRIVILEGES;grant all privileges on . to ‘root’@’%’ identified by 'KaTeX parse error: Expected 'EOF', got '#' at position 173: …mysqld.service #̲用时 endtime=`dat…(date --date=” s t a r t t i m e " + e n d s e c o n d s = starttime" +%s); end_seconds= starttime"+endseconds=(date --date=“ e n d t i m e " + P o r t s t a t u s = ‘ n e t s t a t − l n t u p ∣ g r e p − w " endtime" +%s); Port_status=`netstat -lntup |grep -w " endtime"+Portstatus=netstatlntupgrepw"mysqlport” |wc -l`
if [ P o r t s t a t u s − l t 1 ] t h e n e c h o " = = = = = = = = = = = = = = = = = = = = = = = = = = = = = M y S Q L 安 装 失 败 , 请 排 查 原 因 = = = = = = = = = = = = = = = = = = = = = = = = " e l s e e c h o " = = = = = = = = = = = = = = = = m y s q l 5.7.20 安 装 完 成 , 本 次 安 装 用 时 : " Port_status -lt 1 ] then echo "============================= MySQL安装失败,请排查原因 ========================" else echo "================mysql5.7.20安装完成,本次安装用时: " Portstatuslt1]thenecho"=============================MySQL========================"elseecho"================mysql5.7.20"((end_seconds-start_seconds))“秒===============”
fi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值