Linux上MySQL安装部署

准备工作

在/opt/software目录下创建mysql目录用来存放MySQL安装包:

链接:https://pan.baidu.com/s/1pjc-w6MSNlpptUjsZXNEdQ?pwd=6666

cd /opt/software

mkdir mysql

将安装包上传到mysql目录

安装部署

(1)卸载MySQL依赖,虽然机器上没有装MySQL,但是这一步不可少

yum remove mysql-libs

(2)下载依赖并安装

sudo yum install libaio
sudo yum -y install autoconf

(3)切换到hadoop102的root用户

我一直是用root用户操作的

(4)执行/opt/software/mysql/目录下install_mysql.sh

文件内容如下

#!/bin/bash
set -x
[ "$(whoami)" = "root" ] || exit 1
[ "$(ls *.rpm | wc -l)" = "7" ] || exit 1
test -f mysql-community-client-8.0.31-1.el7.x86_64.rpm && \
test -f mysql-community-client-plugins-8.0.31-1.el7.x86_64.rpm && \
test -f mysql-community-common-8.0.31-1.el7.x86_64.rpm && \
test -f mysql-community-icu-data-files-8.0.31-1.el7.x86_64.rpm && \
test -f mysql-community-libs-8.0.31-1.el7.x86_64.rpm && \
test -f mysql-community-libs-compat-8.0.31-1.el7.x86_64.rpm && \
test -f mysql-community-server-8.0.31-1.el7.x86_64.rpm || exit 1

# 卸载MySQL
systemctl stop mysql mysqld 2>/dev/null
rpm -qa | grep -i 'mysql\|mariadb' | xargs -n1 rpm -e --nodeps 2>/dev/null
rm -rf /var/lib/mysql /var/log/mysqld.log /usr/lib64/mysql /etc/my.cnf /usr/my.cnf

set -e
# 安装并启动MySQL
yum install -y *.rpm >/dev/null 2>&1
systemctl start mysqld

#更改密码级别并重启MySQL
sed -i '/\[mysqld\]/avalidate_password.length=4\nvalidate_password.policy=0' /etc/my.cnf
systemctl restart mysqld

# 更改MySQL配置
tpass=$(cat /var/log/mysqld.log | grep "temporary password" | awk '{print $NF}')
cat << EOF | mysql -uroot -p"${tpass}" --connect-expired-password >/dev/null 2>&1
set password='123456';
update mysql.user set host='%' where user='root';
alter user 'root'@'%' identified with mysql_native_password by '123456';
flush privileges;
EOF

sh install_mysql.sh

(5)登录

输入mysql -uroot -p123456

你可能感兴趣的:(linux,mysql,运维)