编辑安装MySQL

2021/02/07 09:10
阅读数 40

安装包mysql-boost-5.7.20.tar.gz
链接:https://pan.baidu.com/s/1lgQ61Y-lf1UDHiVIPRMIjw
提取码:zqzq

在这里插入图片描述
先装yum域名一键yum源

#!/bin/bash
#编译安装Mysql服务
#使用脚本前注意事项:
#1、请设置好yum源仓库
#2、请在/opt目录下放入mysql-boost-5.7.20.tar.gz安装包

#编写安装mysql的函数
MySQL() {

#关闭系统防火墙和安全机制
systemctl stop firewalld
systemctl disable firewalld
setenforce 0

#安装环境依赖包
yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake

#创建运行用户
useradd -M -s /sbin/nologin  mysql

#编译安装
cd /opt
tar xzvf mysql-boost-5.7.20.tar.gz

cd /opt/mysql-5.7.20/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8  \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1

#编译及安装
make && make install

#修改mysql 配置文件
echo '[client]
port = 3306
socket=/usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES' > /etc/my.cnf


#更改mysql安装目录和配置文件的属主属组
chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf

#设置路径环境变量
echo "export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib">> /etc/profile	
source /etc/profile

#初始化数据库
cd /usr/local/mysql/bin/
./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

#添加mysqld系统服务
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ 

systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld
}


#主体代码
ls /opt | egrep "^mysql-boost-5.7.20.tar.gz$"
if [ $? -eq 0 ];then
  #调用函数安装mysql
  MySQL
  echo "数据库安装完毕,请设定root用户密码。"
  echo "例如:输入“mysqladmin -u root -p password "123456" ” + 回车;回车"

else
  echo -e "请将安装包mysql-boost-5.7.20.tar.gz放入/opt目录下"
  #如果没有就终止
  break
fi

在这里插入图片描述

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部