MySQL 5.7.x 二进制安装
CentOS 7.5
# 创建用户及相关目录
useradd -M -s /sbin/nologin mysql
cd /data/tools/
tar -xvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.23-linux-glibc2.12-x86_64 /data/mysql
mkdir -pv /data/mysql/{data,logs,tmp,binlog}
chown -R mysql.mysql /data/mysql
cd /data/mysql/
./bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/data/mysql \
--datadir=/data/mysql/data \
--socket=/data/mysql/tmp/mysql.sock
# 添加 MySQL 环境变量
vim /etc/profile.d/mysql.sh
#!/bin/bash
export MYSQL_HOME=/data/mysql
export PATH=$PATH:$MYSQL_HOME/bin:$MYSQL_HOME/scripts
:wq
# 重新加载
source /etc/profile
cp /etc/my.cnf /etc/my.cnf_bak
# 创建 systemctl 启动文件
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Community Server
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
Alias=mysql.service
[Service]
User=mysql
Group=mysql
LimitNOFILE=10000
LimitNPROC=10000
PIDFile=/data/mysql/tmp/mysqld.pid
PermissionsStartOnly=true
ExecStart=/data/mysql/bin/mysqld --defaults-file=/etc/my.cnf
TimeoutSec=600
Restart=always
PrivateTmp=false
[Install]
WantedBy=multi-user.target
vim /etc/my.cnf
[client]
# default-character-set = utf8
socket = /data/mysql/tmp/mysql.sock
[mysqld]
basedir = /data/mysql
datadir = /data/mysql/data
port = 3306
socket = /data/mysql/tmp/mysql.sock
pid-file = /data/mysql/tmp/mysqld.pid
log-error = /data/mysql/logs/mysqld.log
# server_id = .....
slow-query-log = on
slow_query_log_file = /data/mysql/logs/slowquery.log
long_query_time = 2
log-queries-not-using-indexes = on
character-set-server = utf8
collation-server = utf8_general_ci
max_connections=1000
default_password_lifetime = 0
# validate_password = off # 关闭 validate-password 功能,第一次启动时,不能开启这个选项,在初始化的时候再开启
# skip-grant-tables # 跳过密码验证
# 启停 MySQL
systemctl daemon-reload
systemctl start mysqld.service
systemctl -l status mysqld
systemctl enable mysqld
systemctl restart mysqld
systemctl stop mysqld
journalctl -fu mysqld
ps -ef | grep mysqld