概述
mysql官网:https://downloads.mysql.com/archives/community/
安装环境
部署ip | 部署软件 | 开放端口 |
---|---|---|
192.168.199.10 | mysql8.0 | 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安装
# 创建mysql用户
userdel mysql
useradd -M -s /sbin/nologin mysql
# 查询是否有mariadb
rpm -qa | grep mariadb
# 卸载mariadb相关软件
rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps
# 安装mysql
mkdir -pv /data/mysql8.0/{temp,logs,data}
tar zxf mysql-8.0.22-el7-x86_64.tar.gz
mv mysql-8.0.22-el7-x86_64 /data/mysql8.0
chown -R mysql:mysql /data/mysql8.0/
# 设置环境变量
echo 'export PATH=/data/mysql8.0/bin:$PATH' >> /etc/profile
# 切换到普通用户
echo 'export PATH=/data/mysql8.0/bin:$PATH' >> ~/.bashrc
# root用户
echo 'export PATH=/data/mysql8.0/bin:$PATH' >> ~/.bashrc
source /etc/profile
基础配置
vim /etc/my.cnf
[mysqld]
port=3306
basedir=/data/mysql8.0
datadir=/data/mysql8.0/data
log-error=/data/mysql8.0/logs/mysql.log
socket=/tmp/mysql.sock
event_scheduler=ON
slow_query_log = ON
slow_query_log_file = /data/mysql8.0/logs/mysql-slow.log
long_query_time = 1
innodb_buffer_pool_size = 6G
default-authentication-plugin=mysql_native_password
server-id=10
log-bin=/data/mysql8.0/logs/mysql-bin
max_connect_errors=1000
log-error=/data/mysql8.0/logs/mysql.log
pid-file=/data/mysql8.0/data/mysql.pid
[client]
#设置客户端编码
default-character-set=utf8
# mysql初始化
mysqld --initialize --user=mysql --basedir=/data/mysql8.0 --datadir=/data/mysql8.0/data/
# mysql初始化后密码查看
cat /data/mysql8.0/logs/mysql.log | grep password
A2UYhWak*Blk
配置启动脚本
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
ExecStart=/data/mysql8.0/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 65536
LimitNPROC = 65536
开机自启设置
# 加入开机启动
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密码修改及权限配置
# 修改root密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'test@2021';
# 给root远程访问权限
update mysql.user set host='%' where user='root';
# 刷新权限
flush privileges;
# 创建普通用户并授权
create user 'test'@'localhost' identified by 'test@2021';
create user 'test'@'%' identified by 'test@2021';
grant all privileges on test01.* to 'test'@'%' with grant option;
grant all privileges on test01.* to 'test'@'localhost' with grant option;
# 刷新权限
flush privileges;