数据库
首页 > 数据库> > Shell 脚本攻略--Mysql 服务(一键部署)(源码编译安装)

Shell 脚本攻略--Mysql 服务(一键部署)(源码编译安装)

作者:互联网

文章目录


准备

cd /opt
#Xshell直接可以“拖进去”
mysql-boost-5.7.20.tar.gz
#这是一个整合包
VMware 16 Pro(16.1.0)
CentOS 7
Xshell 7
本地 Yum 源仓库

一键脚本

cd /opt/
vim mysql.sh

#!/bin/bash

systemctl stop firewalld.service
systemctl disable firewalld.service
setenforce 0
#关闭防火墙(开机禁用)及安全访问策略

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

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

cd /opt
tar zxvf mysql-boost-5.7.20.tar.gz
#解压软件包

cd 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 -j 4 && make install
#编译安装(时间较长!)

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
#更改mysql安装目录和配置文件的属主属组

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

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

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/

systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld
#添加mysql系统服务

netstat -anpt | grep 3306
#检查端口,服务是否正常开启
. mysql.sh
#静静等待即可,主要是编译安装的时间较长
mysqladmin -u root -p password "123123"
#修改mysql登录密码,输入后直接再回车即可

mysql -u root -p
#输入密码后登录
grant all privileges on *.* to 'root'@'%' identified by '123123';
#授权远程登录,密码为'123123'

show databases;
#查看数据库结构
quit
#退出数据库

mysql -uroot -p123123
#可直接登录

标签:ENGINE,Shell,--,源码,mysqld,usr,mysql,DWITH,local
来源: https://blog.csdn.net/weixin_51486343/article/details/113664842