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_%';