Centos7安装Mysql8.4

参考

官方安装文档

卸载 mariadb

yum remove -y mariadb-libs-5.5.68

下载mysql8.4

https://dev.mysql.com/downloads/mysql/
在这里插入图片描述

下载RPM包

wget https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.4-1.el7.x86_64.rpm-bundle.tar

创建解压目录

mkdir -p mysql8.4.4

tar -xvf mysql-8.4.4-1.el7.x86_64.rpm-bundle.tar -C mysql8.4.4
在这里插入图片描述

安装mysql-server

rpm -ivh mysql-community-{server,client,client-plugins,icu-data-files,common,libs}-*

修改基础配置文件

  • 需要先修改配置文件,用于初始化,否则后期修改配置文件中参数与mysql默认参数冲突时,数据库会无法启动。
vim /etc/my.cnf
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# 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 = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

#慢日志
slow_query_log=ON
long_query_time=5
slow_query_log_file=/var/log/mysql-slow.log

##设置缓冲池实例为8个
innodb_buffer_pool_instances=8
#为所有线程打开的表的数量
table_open_cache=65536

#### Threads ###
innodb_purge_threads=4
innodb_page_cleaners=8
innodb_read_io_threads=16
innodb_write_io_threads=16

#### Buffer Cache ###
##### Global ###
##设置缓冲池大小为
innodb_buffer_pool_size=24G
innodb_buffer_pool_chunk_size=128M
innodb_change_buffering=ALL
innodb_change_buffer_max_size=25

#### Connections ###
back_log=1500
max_connections=10000
max_connect_errors=100000
open_files_limit=65535
table_definition_cache=10000
thread_cache_size=1000
#connect_timeout=30
#interactive_timeout=3600
#wait_timeout=3600
#net_read_timeout=86400
#net_write_timeout=86400


### InnoDB Engine ###
###事务隔离级别,默认为可重复读,mysql默认可重复读级别(此级别下可能参数很多间隙锁,影响性能)
transaction_isolation=READ-COMMITTED

# 服务端使用的字符集默认为UTF8
character-set-server=utf8mb4

# 不区分表名大小写
lower_case_table_names=1

# 默认使用“mysql_native_password”插件认证
mysql_native_password=ON
#MySQL 8.4 以上版本
authentication_policy=mysql_native_password
#MySQL 8.0-8.3 版本
#default_authentication_plugin=mysql_native_password

# 关闭DNS解析
skip_name_resolve=ON

# 单个数据包(网络传输或 SQL 语句)的最大值,不建议超过1G,默认值64M
max_allowed_packet=960M

##########################################
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

# 全文检索
innodb_ft_total_cache_size=1600M
innodb_ft_cache_size=80M
innodb_ft_min_token_size=2
ft_min_word_len=2
ngram_token_size=2

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
  • 创建慢日志文件
sudo -u mysql echo "" > /var/log/mysql-slow.log

启动mysqld

systemctl start mysqld

获取默认root密码

grep ‘temporary password’ /var/log/mysqld.log
在这里插入图片描述

登录修改密码

mysql -uroot -p
在这里插入图片描述

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

修改root@localhost,允许远程连接

mysql> use mysql;
mysql> UPDATE user SET host='%' WHERE user='root';
mysql> FLUSH PRIVILEGES;
mysql> exit

重启服务

systemctl restart mysqld

netstat -nltp

在这里插入图片描述

数据库重新初始化

  • 如果修改配置文件后,数据库无法启动时,请检查日志文件,错误例如:
Different lower_case_table_names settings for server ('1') and data dictionary ('0') 

造成原因是,使用默认配置文件初始化数据库,后期又修改配置文件中的lower_case_table_names参数,造成配置冲突。

  • 此时需要重新初始化数据库
    1. 还原默认配置文件,并启动数据库
    2. 登录数据库后,查询 'datadir’路径;
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.4.4 MySQL Community Server - GPL

Copyright (c) 2000, 2025, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW VARIABLES LIKE 'datadir';
+---------------+-----------------+
| Variable_name | Value           |
+---------------+-----------------+
| datadir       | /var/lib/mysql/ |
+---------------+-----------------+
1 row in set (0.01 sec)

mysql> 
  1. 删除数据存储目录下的所有文件;
rm -rf  /var/lib/mysql/*
  1. 初始化数据库;
mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize --console
  1. 查看新密码
[root@centos7-172-028-002-001 log]# grep 'temporary password' /var/log/mysqld.log 
2025-03-18T14:03:20.458408Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: wrV2G*jwLbjy
### 在 CentOS 上手动安装 MySQL 8.4 的教程 #### 准备工作 为了确保顺利安装,在开始前需要确认服务器架构并清理之前的 MySQL 或 MariaDB 安装。 对于查询服务器架构,可以执行如下命令来判断当前系统是 x86_64 架构还是 ARM 架构[^1]: ```bash uname -m ``` 若结果显示 `x86_64` 则表示该机器支持 AMD 和 Intel 处理器;如果是 `aarch64` 则代表这是基于 ARM 的处理器平台。 接着应当移除任何已存在的旧版本 MySQL 或者替代品如 MariaDB。这一步骤可以通过以下指令完成[^2][^4]: ```bash sudo yum remove mariadb* mysql* ``` #### 下载与准备 RPM 包 前往官方提供的链接获取适合于 CentOS 7MySQL Yum Repository 文件,并通过 wget 工具下载它: ```bash wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm ``` 之后利用 rpm 命令导入此仓库文件至本地环境中: ```bash sudo rpm -ivh mysql80-community-release-el7-3.noarch.rpm ``` 此时应该禁用默认启用的 MySQL 社区版更新通道中的最新分支(即 GA 版本),只保留特定的小版本号以便后续指定安装 MySQL 8.4 : ```bash sudo yum-config-manager --disable mysql80-community sudo yum-config-manager --enable mysql80-community&mysql57-community ``` 注意这里假设目标为安装 MySQL 8.4 ,因此还需要进一步调整配置以锁定所需的具体次版本。 #### 正式安装 MySQL 现在可以直接调用 yum 来处理剩余的工作了。由于选择了合适的存储库选项,所以接下来只需简单地输入下面这条语句即可启动整个流程: ```bash sudo yum install mysql-community-server ``` 上述操作不仅会自动解决依赖关系问题,还会创建必要的用户账号以及设置好 mysqld 开机自启项。 #### 启动服务并初始化数据库 一旦安装完毕,则应立即激活新部署的服务实例并且首次运行期间按照提示完成安全设定向导的任务——包括但不限于更改 root 密码等重要事项。 开启 MySQL 数据库服务: ```bash sudo systemctl start mysqld.service ``` 查看临时密码: ```bash grep 'temporary password' /var/log/mysqld.log ``` 最后依照屏幕上的指示逐步强化账户安全性参数直至结束。 #### 验证安装成果 当一切就绪后,尝试登录到刚刚建立起来的新环境当中去验证其可用性状况。 连接到 MySQL 控制台测试是否成功接入: ```bash mysql -u root -p ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值