物理机安装mysql8, 修改数据库目录
自动安装mysql ,并修改数据库目录.
#! /bin/bash
#mysql官方下载路径:https://dev.mysql.com/downloads/mysql/
# 配置dnf源
mkdir -p /etc/yum.repos.d/backup && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
curl http://119.57.77.139:22538/os/x86_64/centos8.repo -o /etc/yum.repos.d/centos8.repo
dnf clean all && dnf makecache
dnf install -y mtr vim bash-completion perl telnet
#解压 & 配置数据目录
tar -xvf mysql-8.0.30-1.el8.x86_64.rpm-bundle.tar
#安装
rpm -ivh mysql-community-common-8.0.30-1.el8.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.30-1.el8.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.30-1.el8.x86_64.rpm
rpm -ivh mysql-community-client-8.0.30-1.el8.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.30-1.el8.x86_64.rpm
rpm -ivh mysql-community-server-8.0.30-1.el8.x86_64.rpm
#初始化配置, 数据目录/data/mysql
mkdir -p /data
sed -i '/.*datadir=*/c\datadir=/data/mysql' /etc/my.cnf
sed -i '/.*socket=*/c\datadir=/data/mysql/mysql.sock' /etc/my.cnf
cp -a /var/lib/mysql /data
echo "正在初始化mysql, 请耐心等候"
mysqld --initialize --console
#修改selinux中数据库目录的上下文
semanage fcontext -a -t mysqld_db_t /data/mysql
semanage fcontext -a -t mysqld_var_run_t '/data/mysql/mysql\.sock'
restorecon -R /data/mysql
#按照原数据目录, 修改所有文件夹和文件的属主权限
chcon -R --reference /var/lib/mysql /data/mysql
chmod -R 777 /data/mysql
#启动
systemctl start mysqld
systemctl enable mysqld
echo "mysql已经启动完成!"
systemctl status mysqld
cat /var/log/mysqld.log | grep password
echo "注意事项:"
echo "请立刻使用命令登陆: mysql -u root -p"
echo "修改初始密码命令: ALTER user 'root'@'localhost' IDENTIFIED BY 'password' ;"