1、下载安装包
wget https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.5-1.el7.x86_64.rpm-bundle.tar
2、解压
mkdir -p /opt/mysql
tar -xvf mysql-8.4.5-1.el7.x86_64.rpm-bundle.tar -C /opt/mysql
3、安装MySQL
3.1、卸载mariadb
rpm -qa | grep mariadb
rpm -e mariadb-connector-c-3.0.6-9.ky10.x86_64 --nodeps
rpm -qa | grep mariadb
3.2、安装依赖
wget http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/compat-openssl10-1.0.2o-4.el8.x86_64.rpmrpm -ivh compat-openssl10-1.0.2o-4.el8.x86_64.rpm --nodeps
3.3、安装MySQL
rpm -ivh mysql-community-common-8.4.5-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.4.5-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.4.5-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.4.5-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.4.5-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.4.5-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.4.5-1.el7.x86_64.rpm
3.4、修改配置
vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.4/en/server-configuration-defaults.html[mysqld]
# 设置3306端口
port=3306
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2Mdatadir=/data/mysql/data
socket=/data/mysql/data/mysql.socklog-error=/data/mysql/log/mysqld.log
pid-file=/data/mysql/mysqld/mysqld.pid# 表,列名大小写不敏感,0为区分大小写
lower_case_table_names=1
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。
max_connect_errors=10
# 服务端使用的字符集默认为utf8mb4
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
socket=/data/mysql/data/mysql.sock
default-character-set=utf8mb4
3.5、初始化MySQL
mkdir -p /data/mysql/{data,log,mysqld}
chown -R mysql:mysql /data/mysql/mysqld --initialize --user=mysql --lower-case-table-names=1systemctl enable mysqld --now# 查看是否开机自启
systemctl is-enabled mysqld.service
3.6、设置远程登陆
grep 'temporary password' /data/mysql/log/mysqld.log
# 修改密码
alter user 'root'@'localhost' identified by 'kylin#2025';# 刷新配置
flush privileges;# 配置远程登陆
CREATE USER 'root'@'%' IDENTIFIED BY 'kylin#2025';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;flush privileges;select user,host,authentication_string from mysql.user where user='root';# 查看字符集
show variables like 'character_set_%';