概述
用于快捷安装MySQL5.7配置。
安装部署
mysql官网:https://downloads.mysql.com/archives/community/
安装环境
部署ip | 部署软件 | 开放端口 |
---|---|---|
192.168.199.10 | mysql-5.7.26 | 3306 |
服务依赖安装
yum install -y cmake make gcc gcc-c++ wget ncurses-devel cmake make perl ncurses-devel openssl-devel bison-devel libaio libaio-devel lrzsz
MySQL安装
tar -zxf mysql-5.7.26-linux-glibc2.12-x86_6ndad4.tar.gz
mv mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql5.7
echo 'export PATH=/usr/local/mysql5.7/bin:$PATH' >> /etc/profile
source /etc/profile
# 切换到普通用户
echo 'export PATH=/usr/local/mysql5.7/bin:$PATH' >> ~/.bashrc
# root用户
echo 'export PATH=/usr/local/mysql5.7/bin:$PATH' >> ~/.bashrc
userdel mysql
useradd -M -s /sbin/nologin mysql
mkdir -pv /data/{temp,log,data}
chown -R mysql:mysql /data
# 初始化数据库,并对目录进行重新授权,如果系统已经存在/etc/my.cnf文件,此步会执行失败,需要将此文件暂时移除后再进行初始化,初始化中的错误不用理会。
mysqld --initialize-insecure --datadir=/data/data --user=mysql
chown -R mysql:mysql /data
完成以上初始化后,检查/datadir/data/目录,是否生成数据库的相关必备的数据库,包括mysql、performance_schema、sys
基础配置
vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql5.7
user=mysql
port=3306
datadir=/data/data
log-error=/data/log/err.log
pid-file=/data/temp/mysqld.pid
socket=/data/temp/mysqld.sock
symbolic-links=0
[client]
socket=/data/temp/mysqld.sock
default-character-set=utf8
配置启动脚本
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=forking
#按实际修改
PIDFile=/data/temp/mysqld.pid
chmod 644 /usr/lib/systemd/system/mysqld.service
开机自启动设置
# 加入开机启动
systemctl daemon-reload
systemctl enable mysqld
# 查看开机是否启动成功
systemctl is-enabled mysqld
# 启动服务
systemctl start mysqld
# 停止服务
systemctl stop mysqld
防火墙开放端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
setenforce 0
mysql密码修改及权限配置
# 创建普通用户并授权
create user 'test'@'%' identified by 'test@2021';
create user 'test'@'localhost' identified by 'test@2021';
grant all on test.* to test@'%' identified by 'test@2021';
grant all on test.* to test@'localhost' identified by 'test@2021';
flush privileges;
# root用户授权
grant all on *.* to root@'%' identified by '123456';
grant all on *.* to root@'localhost' identified by '123456';
flush privileges;
文章来源于互联网:Mysql5.7安装部署及基础配置