运行shell-安装
sh mysql8_install.sh install
#! /bin/bash
function mysql8_install(){
mkdir mysql_rpm
tar -xvf mysql-8.0.26-1.el7.x86_64.rpm-bundle.tar -C mysql_rpm
old_mysql=`rpm -qa | grep mariadb`
rpm -e --nodeps $old_mysql
cd mysql_rpm
rpm -ivh mysql-community-common-8.0.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.26-1.el7.x86_64.rpm
yum install -y net-tools
yum install -y perl
yum install libaio
rpm -ivh mysql-community-server-8.0.26-1.el7.x86_64.rpm
systemctl start mysqld
grep password /var/log/mysqld.log >result.txt
password_mysql=`cat result.txt | grep 'localhost' | tail -n 1 | awk -F ': ' '{print $2}'`
mysql -uroot -p$password_mysql --connect-expired-password <<EOF
set global validate_password.policy=LOW;
set global validate_password.length=4;
alter user root@localhost identified by '123456';
create user 'root'@'%' identified by '123456';
grant all privileges on *.* to 'root'@'%' with grant option;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
flush privileges;
quit
EOF
}
function mysql8_uninstall(){
systemctl stop mysqld
list1=`rpm -qa | grep mysql`
for a1 in $list1
do
echo "卸载:$a1"
yum remove -y $a1
done
list2=`find / -name mysql`
for a2 in $list2
do
echo "删除: $a2"
rm -rf $a2
done
}
if [ "$1" = "install" ]
then
echo '开始安装'
mysql8_install
elif [ "$1" = "uninstall" ]
then
echo '开始卸载'
mysql8_uninstall
else
echo '参数错误'