MySQL安装

RPM安装

  • 软件包下载

下载地址MySQL社区版open in new window

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.31-1.el7.x86_64.rpm-bundle.tar
# 下载MySQL版本为8.0.31

tar -xvf mysql-9.0.31-1.el7.x86_64.rpm-bundle.tar
# 解压软件tar包
  • 软件包内容

mysql-community-client-8.0.31-1.el7.x86_64.rpm # MySQL客户端工具
mysql-community-client-plugins-8.0.31-1.el7.x86_64.rpm # MySQL客户端插件
mysql-community-common-8.0.31-1.el7.x86_64.rpm # 服务器客户端通用库
mysql-community-debuginfo-8.0.31-1.el7.x86_64.rpm
mysql-community-devel-8.0.31-1.el7.x86_64.rpm # MySQL开发相关工具
mysql-community-embedded-compat-8.0.31-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.31-1.el7.x86_64.rpm # Unicode库
mysql-community-libs-8.0.31-1.el7.x86_64.rpm # 客户端应用程序共享库 
mysql-community-libs-compat-8.0.31-1.el7.x86_64.rpm
mysql-community-server-8.0.31-1.el7.x86_64.rpm # 数据库服务器
mysql-community-server-debug-8.0.31-1.el7.x86_64.rpm
mysql-community-test-8.0.31-1.el7.x86_64.rpm # MySQL服务器测试工具
  • 软件包安装

    • 安装前需卸载 Mariadb
    • RPM 安装需按固定顺序安装
生产环境
# 查询是否安装Mariadb
rpm -qa | grep mariadb

# 查询结果
mariadb-libs-5.5.68-1.el7.x86_64

# 卸载Mariadb
yum remove mariadb-libs

# 服务器客户端通用库
rpm -ivh mysql-community-common-8.0.31-1.el7.x86_64.rpm --force --nodeps

# MySQL客户端插件
rpm -ivh mysql-community-client-plugins-8.0.31-1.el7.x86_64.rpm --force --nodeps

# 客户端应用程序共享库 
rpm -ivh mysql-community-libs-8.0.31-1.el7.x86_64.rpm --force --nodeps

# MySQL客户端工具
rpm -ivh mysql-community-client-8.0.31-1.el7.x86_64.rpm --force --nodeps

# ICU数据文件
rpm -ivh mysql-community-icu-data-files-8.0.31-1.el7.x86_64.rpm --force --nodeps

# 数据库服务器
rpm -ivh mysql-community-server-8.0.31-1.el7.x86_64.rpm --force --nodeps
开发环境

开发环境可选安装工具包

# MySQL开发相关工具
rpm -ivh mysql-community-devel-8.0.31-1.el7.x86_64.rpm --force --nodeps

# MySQL服务器测试工具
rpm -ivh mysql-community-test-8.0.31-1.el7.x86_64.rpm --force --nodeps

MySQL初始化

MySQL安装完成后需运行 安全配置脚本

# 安装完成启动 Mysql
systemctl start mysqld

# 运行安全配置向导
/usr/bin/mysql_secure_installation

# 步骤 1 输入root密码 在/var/log/mysqld.log
Enter password for user root:

# root新密码(输入密码)
New password:

# 重复新密码(输入密码)
Re-enter new password:

# 确认是否修改密码(yes)
Change the password for root ? ((Press y|Y for Yes, any other key for No) :

# 是否删除匿名用户(yes)
Remove anonymous users? (Press y|Y for Yes, any other key for No) :

# 禁止root用户远程登录(根据情况)
Disallow root login remotely? (Press y|Y for Yes, any other key for No) :

# 删除测试数据库(yes)
Remove test database and access to it? (Press y|Y for Yes, any other key for No) :

# 重新加载权限表(yes)
Reload privilege tables now? (Press y|Y for Yes, any other key for No) :

MySQL完全卸载

# 停止服务
systemctl stop mysqld

# 查询MySQL服务
rpm -qa | grep -i mysql

# 依次卸载
rpm -e 软件包

# 查找MySQL相关目录
find / -name mysql

# 依次删除
rm -rf /目录

# 删除配置文件
rm -rf /etc/my.cnf