标签:key use 上传 ash nec rpm 生成 查看 --
以下脚本的手动安装连接:https://www.cnblogs.com/leihongnu/p/12581793.html
【
#/bin/bash
#脚本安装 mysql,上传安装包至 /root
cd /root
#安装日志
mysql_log=/root/mysql.log
# mysql 安装包名
mysql_package=mysql-8.0.19-linux-glibc2.12-x86_64.tar.xz
# 解压 mysql 安装包后文件夹名称
mysql_package_dir=mysql-8.0.19-linux-glibc2.12-x86_64
#存放数据库的目录
mysql_dbdata=/usr/local/mysql/data
#centos6 检查 mysql
if [ `rpm -qa | grep -i mysql | wc -l ` -ge 1 ]
then
rpm -qa | grep -i mysql >> uninstall_mysql.txt
file=$(cat uninstall_mysql.txt)
for name in $file
do
rpm -e --nodeps $name
done
fi
rm -rf uninstall_mysql.txt
#centos7 检查 mariadb
if [ `rpm -qa | grep -i mariadb | wc -l ` -ge 1 ]
then
rpm -qa | grep -i mariadb >> uninstall_mariadb.txt
file=$(cat uninstall_mariadb.txt)
for name in $file
do
rpm -e --nodeps $name
done
fi
rm -rf uninstall_mariadb.txt
#添加 mysql 用户
useradd -r -s /sbin/nologin mysql
#解压 mysql_package 至 /usr/local
tar -xvf $mysql_package -C /usr/local/
cd /usr/local
#创建软连接
ln -s $mysql_package_dir mysql
#创建 mysql 数据存放目录
mkdir $mysql_dbdata
#修改文件夹所属者
chown -R mysql:mysql mysql
chown -R mysql:mysql mysql/
#添加环境变量路径,使生效
echo PATH=/usr/local/mysql/bin:$PATH > /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
#生成数据库,默认生成密码打印在屏幕上,登录时会用到,记得保存
cd /usr/local/mysql
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=$mysql_dbdata
#创建RSA private key
bin/mysql_ssl_rsa_setup --datadir=$mysql_dbdata
#生成配置文件
if [ -e /etc/my.cnf ]
then
mv /etc/my.cnf /etc/my.cnf.bak
rm -rf /etc/my.cnf
fi
touch /etc/my.cnf
echo "[client]" >> /etc/my.cnf
echo "port = 3306" >> /etc/my.cnf
echo "default-character-set=utf8" >> /etc/my.cnf
echo "[mysqld]" >> /etc/my.cnf
echo "character_set_server=utf8" >> /etc/my.cnf
echo "init_connect=‘SET NAMES utf8‘" >> /etc/my.cnf
echo "basedir=/usr/local/mysql" >> /etc/my.cnf
echo "datadir=/usr/local/mysql/$mysql_dbdata" >> /etc/my.cnf
echo "socket=/tmp/mysql.sock" >> /etc/my.cnf
echo "[mysqld_safe]" >> /etc/my.cnf
echo "lower_case_table_names = 1" >> /etc/my.cnf
echo "log-error=/var/log/mysqld.log" >> /etc/my.cnf
echo "pid-file=/var/run/mysqld/mysqld.pid" >> /etc/my.cnf
#设置启动服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#添加启动服务
chkconfig --add mysqld
#启动服务
service mysqld start
#查看服务
systemctl status mysqld >> $mysql_log
】
标签:key use 上传 ash nec rpm 生成 查看 --
原文地址:https://www.cnblogs.com/leihongnu/p/13024644.html