linux7.6安装mysql 8.20 脚本安装

linux7.6安装mysql 8.20
1.安装前环境准备

如果以前使用操作系统本机软件包管理系统(例如Yum或APT)安装了MySQL,则在使用本机二进制文件安装时可能会遇到问题。 
确保以前的MySQL安装已完全删除(使用程序包管理系统),并且所有其他文件(例如数据文件的旧版本)也已删除。您还应
该检查配置文件(例如/etc/my.cnf或/ etc / mysql目录)并将其删除。

MySQL依赖libaio库。 如果未在本地安装此库,则数据目录初始化和随后的服务器启动步骤将失败。 
所以centos、redhat安装时需要先安装上libaio库
 yum install libaio # install library
如果是ubuntu系统:
apt-get install libaio1 # install library
如果系统是Oracle Linux 8 / Red Hat 8 (EL8): These platforms by default do not install the file /lib64/libtinfo.so.5, which is required by the MySQL client bin/mysql for packages mysql-VERSION-el7-x86_64.tar.gz and mysql-VERSION-linux-glibc2.12-x86_64.tar.xz. To work around this issue, install the ncurses-compat-libs package:
 yum install ncurses-compat-libs
 2. 安装脚本
groupadd mysql
useradd -r -g mysql -s /bin/false mysql --useradd -r 增加系统用户,系统用户与普通用户的区别,系统账户的用户id一般是小于一千的;系统用户就是给UID一个确定的代号,它不能用于登录,一般是给程序来使用,其他的系统用户与普通用户没其他不同。
cd /usr/local
tar xvf /path/to/mysql-VERSION-OS.tar.xz
ln -s full-path-to-mysql-VERSION-OS mysql
cd mysql
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
bin/mysqld --initialize --user=mysql
bin/mysql_ssl_rsa_setup
bin/mysqld_safe --user=mysql &
cp support-files/mysql.server /etc/init.d/mysql.server


3.编写的mysql自动安装脚本
#!/bin/bash
if [ ! $1 ] || [ ! $2 ] 
then  
   echo -e "execute \033[31;40m[error]\033[0m,请输入压缩包路径和数据文件路径" 
   exit
fi
jg=`rpm -qa|grep libaio`
if [ ! $jg  ];then
echo 'libaio is no exsit'
exit
fi
groupadd mysql >>/root/mysqlerror.log 2>&1
useradd -r -g mysql -s /bin/false mysql >>/root/mysqlerror.log 2>&1
if [ ! -f $1 ]; then
echo 'mysql安装压缩包不存在,请重新执行,输入正确地址'
exit 0
fi
if [ ! -d $2 ];then
echo -e "数据文件目录不存在,创建$2"
mkdir -p $2
fi
##判断服务器是否已存在mysql
mysql_running=$(ps -ef|grep -i mysqld|grep -v grep|wc -l)
if [ "${mysql_running}" -gt "0" ]; then
echo '此服务器已经存在mysql数据库!'
exit 
fi
##判断mysqlbase目录是否已存在
if [  -d /usr/local/mysql ]; then
echo -n 'mysqlbase目录已存在,是否更换base目录? 请输入,y或n:'
read huifu
  if [ $huifu = 'y' ];then
echo -n '请输入mysqlbase路径:'
read install_path
tar -xf $1 -C $install_path
else
exit 0
  fi
echo "mysql初始化完成……"
else
tar -xf $1 -C /usr/local/
name=`ls -d mysql-*x86_64`
ln -s /usr/local/$name /usr/local/mysql
fi

if [ ! $install_path  ];then
cd /usr/local/mysql/
bin/mysqld --initialize --user=mysql  --basedir=/usr/local/mysql --datadir=$2
cp support-files/mysql.server /etc/init.d/mysqld
sed -i 's#^basedir=$#basedir=/usr/local/mysql#g' /etc/init.d/mysqld
sed -i "s#^datadir=\$#datadir=$2#g" /etc/init.d/mysqld
else 
cd $install_path
name=`ls -d mysql-*x86_64`
cd $name
baselj=`echo $install_path/$name`
bin/mysqld --initialize --user=mysql  --basedir=/usr/local/mysql --datadir=$2
cp support-files/mysql.server /etc/init.d/mysqld
sed -i "s#^basedir=\$#basedir=$baselj#g" /etc/init.d/mysqld
sed -i "s#^datadir=\$#datadir=$2#g" /etc/init.d/mysqld
fi
echo 'MySql初始化完成'

4.再配置/etc/my.cnf

[mysqld]
datadir=/opt/mysql/data
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
federated
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#autocommit=0
innodb_large_prefix=on
innodb_file_format=Barracuda
character-set-server=utf8
collation-server=utf8_general_ci
ft_min_word_len=1
default-storage-engine=INNODB
key_buffer_size = 256M
max_allowed_packet = 256M
thread_stack = 192K
thread_cache_size = 8
expire_logs_days=30
sort_buffer_size = 20M
read_buffer_size = 20M
read_rnd_buffer_size = 8M
innodb_log_file_size=1G
innodb_log_files_in_group=6
max_connections = 2000
server-id=202
log-bin=mysql-bin
binlog_format=row
innodb_file_per_table=1
innodb_support_xa=1
sync_binlog=100
innodb_buffer_pool_size = 100G
innodb_flush_log_at_trx_commit=2
log-slave-updates
transaction-isolation=Read-Committed
lower_case_table_names=1
log_timestamps=SYSTEM
slave-parallel-type=LOGICAL_CLOCK
slave-parallel-workers=8
master_info_repository=TABLE
relay_log_info_repository=TABLE
relay_log_recovery=ON
sync_relay_log=100
log_error_verbosity=2
secure_file_priv=''
innodb_adaptive_hash_index=0

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值