安装MySQL5.7.26
MySQL下载教程请参考:https://www.cnblogs.com/dbbull/p/14815360.html
安装MySQL5.7.26
。创建MySQL虚拟用户
useradd -s /sbin/nologin -M mysql
id mysql
。创建目录
mkdir -p /server/tools
mkdir -p /opt/mysql
mkdir -p /data/mysql/mysql3306/{data,logs}
cd /server/tools
#生成序列:mkdir {a..e}
#取列:ifconfig eth0 | awk -F' ' 'NR==2{print $2}'
。上传二进制包
rz
yum install -y lrzsz
。解压二进制包
tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
#磁盘空间不足:df -h or df -i
。将软件部分移动到指定目录
mv mysql-5.7.26-linux-glibc2.12-x86_64 /opt/mysql/mysql-5.7.26
。创建软连接
ln -s /opt/mysql/mysql-5.7.26/ /usr/local/mysql
。删除mariadb
rpm -e --nodeps mariadb-libs
。配置文件整理
vim /data/mysql/mysql3306/my3306.cnf
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql/mysql3306/data
socket = /data/mysql/mysql3306/mysql.sock
server_id = 1
port = 3306
log_error=/data/mysql/mysql3306/logs/error.log
log_bin=/data/mysql/mysql3306/logs/mysql-bin
binlog_format=row
gtid_mode=on
enforce_gtid_consistency=true
log_slave_updates=1
max_connections=1024
wait_timeout=60
sort_buffer_size=2M
max_allowed_packet=32M
join_buffer_size=2M
innodb_buffer_pool_size=128M
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=32M
innodb_log_file_size=128M
innodb_log_files_in_group=2
binlog_cache_size=2M
max_binlog_cache_size=8M
max_binlog_size=512M
expire_logs_days=7
slow_query_log=on
slow_query_log_file=/data/mysql/mysql3306/logs/slow.log
long_query_time=0.5
log_queries_not_using_indexes=1
。安装MySQL依赖包
yum install libaio-devel -y
yum install numactl -y
。更改MySQL相关目录的用户组
chown -R mysql:mysql /data/*
。初始化数据库
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/mysql3306/data
。加入环境变量
vim /etc/profile
export PATH="/usr/local/mysql/bin:$PATH"
source /etc/profile
。启动MySQL
mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf &
。查看是否启动成功
netstat -lntup |grep mysql
。连接mysql
mysql -S /data/mysql/mysql3306/mysql.sock