一键安装MySQL5.7
Mysql5.7.30安装
操作系统
CentOS7
脚本如下
vim install_mysql.sh
#!/bin/bash
#定义安装软件版本
MYSQL_V=5.7.30
#定义临时目录
TMP_DIR=/tmp
PWD_C=$PWD
echo
echo -e "\tMenu\n"
echo -e "1. Install MySQL"
echo -e "2. Quit"
#定义函数
function command_status_check() {
if [ $? -ne 0 ]; then
echo $1
exit
fi
}
function install_mysql() {
cd $TMP_DIR
yum install numactl ncurses-devel libaio-devel -y
yum remove mariadb-libs -y
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
tar -xvf mysql-${MYSQL_V}-linux-glibc2.12-x86_64.tar.gz
mv mysql-${MYSQL_V}-linux-glibc2.12-x86_64 /web/mysql
grep mysql /etc/passwd
RETVAL=$?
if [ $RETVAL -ne 0 ];then
useradd mysql -s /sbin/nologin -M
echo "mysql user added successfully!"
else
echo " $(echo -e "\e[31;47;5m mysql user already exists\e[0m")"
echo " $(echo -e "\e[31;47;5m Don't worry,continue......\e[0m")"
fi
mkdir -p /web/mysql/{binlog,data,logs}
chown -R mysql:mysql /web/mysql
chown -R mysql:mysql /web/mysql/*
cat >>/etc/my.cnf<<EOF
[client]
port = 3306
[mysqld]
user =mysql
basedir =/web/mysql/
datadir =/web/mysql/data
server_id =6
port =3306
character_set_server =utf8
socket =/tmp/mysql.sock
read_only =0
skip_name_resolve =1
auto_increment_increment =1
auto_increment_offset =1
lower_case_table_names =1
open_files_limit =65536
max_connections =2048
####: for binlog
binlog_format =row
log_bin =/web/mysql/binlog/mysql-bin
binlog_rows_query_log_events =on
log_slave_updates =on
expire_logs_days =7
binlog_cache_size =65536
sync_binlog =1
slave-preserve-commit-order =ON
####: for error-log
log_error =/web/mysql/logs/error.log
general_log =off
general_log_file =/web/mysql/logs/general.log
####: for slow query log
slow_query_log =on
slow_query_log_file =/web/mysql/logs/slow.log
long_query_time =1.000000
####: for gtid
gtid_mode =on
enforce_gtid_consistency =on
EOF
#数据库初始化,初始化的密码为空
/web/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/web/mysql --datadir=/web/mysql/data
command_status_check "MySQL - 初始化失败!"
cp /web/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
/etc/init.d/mysqld start
command_status_check "MySQL - 启动失败!"
#添加环境变量,命令行需要手动执行source /etc/profile以使环境变量生效
echo 'export PATH=/web/mysql/bin:$PATH' >> /etc/profile
}
read -p "请输入编号:" number
case $number in
1)
install_mysql;;
2)
exit;;
esac
授权可执行权限
chmod +x install_mysql.sh
安装mysql
./install_mysql.sh
时间稍微长点,耐心等待。。。
安装完成
默认密码为空
登录
source /etc/profile
mysql -u root -p
修改密码
mysqladmin -u root -p password
停止mysql
/etc/init.d/mysqld stop
启动mysql
/etc/init.d/mysqld start
重启mysql
/etc/init.d/mysqld restart
查看mysql版本
select version();
至此MySQL5.7安装完成,感谢观看!
本文来自博客园,作者:霸都运维,转载请注明原文链接:https://www.cnblogs.com/wangjie20200529/p/16377572.html