MySQL下载教程请参考:http://xiazai.cuohei.com/
。创建MySQL虚拟用户
useradd -s /sbin/nologin -M mysql
。创建目录
mkdir -p /server/tools
mkdir -p /opt/mysql
mkdir -p /data/mysql/mysql3306/{data,logs}
cd /server/tools
#课堂小知识:
快速备份:cp a.txt{,.bak}
删除文件:通过mv代替rm,将文件移动到/tmp目录下,等确认该文件后期不再使用,可以进入/tmp目录通过rm进行删除
。上传二进制包
rz
yum install -y lrzsz
。解压二进制包
tar xf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
。将软件部分移动到指定目录
mv mysql-8.0.20-linux-glibc2.12-x86_64 /opt/mysql/mysql-8.0.20
。创建软连接
ln -s /opt/mysql/mysql-8.0.20/ /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