环境

系统 RedHat 8.6

数据库版本 MySQL Server 8.0.36 TAR for Generic Linux (glibc2.28)

检查glibc版本

rpm -qa|grep glibc

#回显

glibc-2.28-189.5.el8_6.x86_64

目录结构

/data/mysqlsoft 安装文件

/data/mysqldata 数据文件

/data/mysqllogs log文件和其它文件

/data/mysqlbak 备份文件


#安装

yum install libaio ncurses-compat-libs net-tools


cat /etc/hosts

#回显包含

127.0.0.1 localhost

#创建用户

groupadd -g 690001 mysql

useradd -r -g mysql -s /bin/false -u 690001 mysql

#如果服务器内存比较大,需要配置大内存页。(后续加,此步骤略)

#创建目录

mkdir -p /data/{mysqlsoft,mysqldata,mysqllogs,mysqlbak}

mkdir -p /data/mysqlsoft/mysql_install

cd /data/mysqlsoft/mysql_install

mv 'MySQL Commercial Server 8.0.36 TAR for Generic Linux (glibc2.28) x86.zip' mysql8e_36.zip

unzip mysql8e_36.zip

md5sum -c mysql-commercial-8.0.36-linux-glibc2.28-x86_64.tar.xz.md5

tar xvf mysql-commercial-8.0.36-linux-glibc2.28-x86_64.tar.xz -C /data/mysqlsoft

mv /data/mysqlsoft/mysql-commercial-8.0.36-linux-glibc2.28-x86_64/ /data/mysqlsoft/mysql8e-36

ln -s /data/mysqlsoft/mysql8e-36 /usr/local/mysql

echo "#MYSQL_ADD_PATH" >> ~/.bash_profile

echo 'PATH=$PATH:$HOME/bin:/usr/local/mysql/bin' >> ~/.bash_profile

echo 'export PATH' >> ~/.bash_profile

tail -n 5 ~/.bash_profile

#PATH=$PATH:$HOME/bin

#export PATH

. ~/.bash_profile

mysql -V

#回显

mysql Ver 8.0.36-commercial for Linux on x86_64 (MySQL Enterprise Server - Commercial)

#设置目录权限

chown mysql:mysql -R /data/{mysqlsoft,mysqldata,mysqllogs,mysqlbak}

chmod 750 -R /data/{mysqlsoft,mysqldata,mysqllogs,mysqlbak}

chgrp -R mysql /data/{mysqlsoft,mysqldata,mysqllogs,mysqlbak}

mkdir /etc/my.cnf.d

chown mysql:mysql -R /etc/my.cnf.d/

chmod 750 -R /etc/my.cnf.d/

chown mysql:mysql /data/mysqlsoft/my.cnf

#添加my.cnf配置文件,字符集使用utf8mb4。(优化配置后续)

[mysqld]
server_id = 1
port = 3306
user = mysql
log_bin=/data/mysqllogs/logbin.log
slow_query_log = on
slow_launch_time = 5
slow_query_log_file = /data/mysqllogs/slow_logs.log
binlog_cache_size = 1g
max_binlog_cache_size = 4G
character-set-server = utf8mb4
collation-server = utf8mb4_bin
default-time-zone = '+08:00'
max_connections = 1000
max_connect_errors = 20
default-storage-engine = INNODB
innodb_max_dirty_pages_pct = 50

datadir = /data/mysqldata
log-error = /data/mysqllogs/mysql-error.log
pid-file = /data/mysqllogs/mysqld.pid
socket = /tmp/mysql.sock

join_buffer_size = 1G
sort_buffer_size = 1M
innodb-buffer-pool-size = 8G
innodb-buffer-pool-instances = 16
innodb_buffer-pool-chunk-size = 128M
innodb-redo-log-capacity = 8G
innodb-rollback-segments = 2

innodb_fast_shutdown = 0

tls_version = ''
[mysql]

[client]
port = 3306

[client-server]
!includedir /etc/my.cnf.d

chmod 750 /data/mysqlsoft/my.cnf

chown mysql:mysql /data/mysqlsoft/my.cnf

mv /etc/my.cnf /data/mysqlsoft/my.cnf.old

ln -s /data/mysqlsoft/my.cnf /etc/my.cnf

ll /etc/my.cnf

#回显

lrwxrwxrwx 1 root root 22 Jan 19 09:56 /etc/my.cnf -> /data/mysqlsoft/my.cnf

#启动服务

systemctl start mysqld

#初始化安装

mysqld --initialize-insecure --user=mysql

#查看是否存在错误

cat /data/mysqllogs/mysql-error.log |grep ERROR

添加开机启动服务

cp /data/mysqlsoft/mysql8e-36/support-files/mysql.server /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig --level 345 mysqld on

systemctl status mysqld

#设置密码

mysql -u root --skip-password

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '复杂密码';

#验证密码

mysqladmin -uroot -p version

#安全配置

mysql_secure_installation

#查看log日志使用

mysql> SHOW BINARY LOGS;

查看字符集

mysql> SHOW VARIABLES LIKE 'character_set%';