1 访问网站 https://downloads.mysql.com/archives/community/ 选择合适的版本,点击 Download。
2 上传下载好的 mysql-5.7.44-1.el7.x86_64.rpm-bundle.tar 文件到 Centos7 机器,这里放到了 下载 目录。
3 解压 mysql-5.7.44-1.el7.x86_64.rpm-bundle.tar。
[root@localhost 下载]# tar -xvf mysql-5.7.44-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-5.7.44-1.el7.x86_64.rpm
mysql-community-common-5.7.44-1.el7.x86_64.rpm
mysql-community-devel-5.7.44-1.el7.x86_64.rpm
mysql-community-embedded-5.7.44-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.44-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.44-1.el7.x86_64.rpm
mysql-community-libs-5.7.44-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.44-1.el7.x86_64.rpm
mysql-community-server-5.7.44-1.el7.x86_64.rpm
mysql-community-test-5.7.44-1.el7.x86_64.rpm
[root@localhost 下载]# ls
mysql-5.7.44-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-5.7.44-1.el7.x86_64.rpm
mysql-community-common-5.7.44-1.el7.x86_64.rpm
mysql-community-devel-5.7.44-1.el7.x86_64.rpm
mysql-community-embedded-5.7.44-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.44-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.44-1.el7.x86_64.rpm
mysql-community-libs-5.7.44-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.44-1.el7.x86_64.rpm
mysql-community-server-5.7.44-1.el7.x86_64.rpm
mysql-community-test-5.7.44-1.el7.x86_64.rpm
4 安装 对应的 rpm。
[root@localhost 下载]# yum install mysql-community-{server,client,common,libs}-*
已加载插件:fastestmirror, langpacks
正在检查 mysql-community-server-5.7.44-1.el7.x86_64.rpm: mysql-community-server-5.7.44-1.el7.x86_64
mysql-community-server-5.7.44-1.el7.x86_64.rpm 将被安装
正在检查 mysql-community-client-5.7.44-1.el7.x86_64.rpm: mysql-community-client-5.7.44-1.el7.x86_64
mysql-community-client-5.7.44-1.el7.x86_64.rpm 将被安装
正在检查 mysql-community-common-5.7.44-1.el7.x86_64.rpm: mysql-community-common-5.7.44-1.el7.x86_64
mysql-community-common-5.7.44-1.el7.x86_64.rpm 将被安装
正在检查 mysql-community-libs-5.7.44-1.el7.x86_64.rpm: mysql-community-libs-5.7.44-1.el7.x86_64
mysql-community-libs-5.7.44-1.el7.x86_64.rpm 将被安装
正在检查 mysql-community-libs-compat-5.7.44-1.el7.x86_64.rpm: mysql-community-libs-compat-5.7.44-1.el7.x86_64
mysql-community-libs-compat-5.7.44-1.el7.x86_64.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-client.x86_64.0.5.7.44-1.el7 将被 安装
---> 软件包 mysql-community-common.x86_64.0.5.7.44-1.el7 将被 安装
---> 软件包 mysql-community-libs.x86_64.0.5.7.44-1.el7 将被 安装
---> 软件包 mysql-community-libs-compat.x86_64.0.5.7.44-1.el7 将被 安装
---> 软件包 mysql-community-server.x86_64.0.5.7.44-1.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
===================================================================================================
Package 架构 版本 源 大小
===================================================================================================
正在安装:
mysql-community-client x86_64 5.7.44-1.el7 /mysql-community-client-5.7.44-1.el7.x86_64 120 M
mysql-community-common x86_64 5.7.44-1.el7 /mysql-community-common-5.7.44-1.el7.x86_64 2.8 M
mysql-community-libs x86_64 5.7.44-1.el7 /mysql-community-libs-5.7.44-1.el7.x86_64 11 M
mysql-community-libs-compat
x86_64 5.7.44-1.el7 /mysql-community-libs-compat-5.7.44-1.el7.x86_64 6.0 M
mysql-community-server x86_64 5.7.44-1.el7 /mysql-community-server-5.7.44-1.el7.x86_64 796 M
事务概要
===================================================================================================
安装 5 软件包
总计:936 M
安装大小:936 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : mysql-community-common-5.7.44-1.el7.x86_64 1/5
正在安装 : mysql-community-libs-5.7.44-1.el7.x86_64 2/5
正在安装 : mysql-community-client-5.7.44-1.el7.x86_64 3/5
正在安装 : mysql-community-server-5.7.44-1.el7.x86_64 4/5
正在安装 : mysql-community-libs-compat-5.7.44-1.el7.x86_64 5/5
验证中 : mysql-community-server-5.7.44-1.el7.x86_64 1/5
验证中 : mysql-community-libs-compat-5.7.44-1.el7.x86_64 2/5
验证中 : mysql-community-client-5.7.44-1.el7.x86_64 3/5
验证中 : mysql-community-libs-5.7.44-1.el7.x86_64 4/5
验证中 : mysql-community-common-5.7.44-1.el7.x86_64 5/5
已安装:
mysql-community-client.x86_64 0:5.7.44-1.el7 mysql-community-common.x86_64 0:5.7.44-1.el7
mysql-community-libs.x86_64 0:5.7.44-1.el7 mysql-community-libs-compat.x86_64 0:5.7.44-1.el7
mysql-community-server.x86_64 0:5.7.44-1.el7
完毕!
5 启动并检查状态。
[root@localhost 下载]# systemctl start mysqld
[root@localhost 下载]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 三 2024-05-08 11:54:45 CST; 9s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 26819 ExecStart=/usr/sbin/mysqld --daemonize --pid-
file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 26757 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 26821 (mysqld)
Tasks: 27
CGroup: /system.slice/mysqld.service
└─26821 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
5月 08 11:54:31 localhost.localdomain systemd[1]: Starting MySQL Server...
5月 08 11:54:45 localhost.localdomain systemd[1]: Started MySQL Server.
6 查看临时密码,并登陆,设置新密码(1qasw2#ED 为新密码),授权远程访问。
[root@localhost 下载]# sudo grep 'temporary password' /var/log/mysqld.log
2024-05-08T03:54:40.275528Z 1 [Note] A temporary password is generated for root@localhost:
xjm5_sATw(yn
[root@localhost 下载]# mysql -u root -p
Enter password:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '1qasw2#ED';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '1qasw2#ED' WITH GRANT
OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
Bye
7 设置开机自启动。
[root@localhost 下载]# systemctl enable mysqld
[root@localhost 下载]# systemctl daemon-reload
8 修改配置文件字符集编码为 utf8mb4。
[root@localhost 下载]# vim /etc/my.cnf
增加内容:
[mysql]
default-character-set=utf8mb4
[mysqld]
default-storage-engine=INNODB
character_set_server=utf8mb4
9 重启服务。
[root@localhost 下载]# systemctl restart mysqld
10 防火墙开放 3306 端口。
[root@localhost 下载]# firewall-cmd --state
running
[root@localhost 下载]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost 下载]# firewall-cmd --reload
success
########################################################################
附录:
数据库命令:
service mysqld status
service mysqld start
service mysqld stop
service mysqld restart
systemctl status mysqld
systemctl start mysqld
systemctl stop mysqld
systemctl restart mysqld
mysql 源
http://repo.mysql.com/
使用 MySQL 源方式:
[root@localhost 下载]# wget https://dev.mysql.com/get/mysql80-community-release-el7-11.noarch.rpm
[root@localhost 下载]# yum localinstall mysql80-community-release-el7-11.noarch.rpm
[root@localhost 下载]# ls /etc/yum.repos.d
[root@localhost 下载]# yum repolist all | grep mysql
[root@localhost 下载]# yum-config-manager --disable mysql80-community
[root@localhost 下载]# yum-config-manager --enable mysql57-community
[root@localhost 下载]# yum repolist all | grep mysql
[root@localhost 下载]# yum install -y mysql-community-server
使用 rpm 方式:
[root@localhost 下载]# tar -xvf mysql-5.7.44-1.el7.x86_64.rpm-bundle.tar
[root@localhost 下载]# yum install mysql-community-{server,client,common,libs}-*
[root@localhost 下载]# systemctl start mysqld
[root@localhost 下载]# systemctl status mysqld
[root@localhost 下载]# sudo grep 'temporary password' /var/log/mysqld.log
########################################################################
# 1 卸载 mysql
[root@localhost 下载]# yum list installed|grep mysql
mysql-community-client.x86_64 5.7.44-1.el7 @mysql57-community
mysql-community-common.x86_64 5.7.44-1.el7 @mysql57-community
mysql-community-libs.x86_64 5.7.44-1.el7 @mysql57-community
mysql-community-server.x86_64 5.7.44-1.el7 @mysql57-community
mysql80-community-release.noarch el7-11 @/mysql80-community-release-el7-11.noarch
[root@localhost 下载]# yum remove mysql-community-client.x86_64
[root@localhost 下载]# yum remove mysql-community-common.x86_64
[root@localhost 下载]# yum remove mysql80-community-release.noarch
# 删除多余的文件
[root@localhost 下载]# rm -rf /var/lib/mysql
[root@localhost 下载]# rm -rf /var/log/mysqld.log
# 2 卸载 mariadb
## 2.1 使用 yum 卸载
[root@localhost /]# yum list installed|grep mariadb
mariadb-libs.x86_64 1:5.5.68-1.el7 @anaconda
[root@localhost /]# yum remove mariadb-libs.x86_64
## 2.2 使用 rpm 卸载:
[root@localhost /]# rpm -qa | grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost /]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
########################################################################
# MySQL5.7
ALTER USER '用户名'@'localhost' IDENTIFIED BY '新密码';
FLUSH PRIVILEGES;
# MySQL8.0
ALTER USER '用户名'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
FLUSH PRIVILEGES;
# 跳过密码输入
[mysqld]
skip-grant-tables
重启登录,然后更改密码。
########################################################################
参考:
MySQL官网
https://dev.mysql.com/doc/refman/8.4/en/linux-installation-yum-repo.html
centos7 安装 Mysql 5.7.28,详细完整教程
https://blog.csdn.net/xiaoweite1/article/details/103555491
CentOS7安装MySQL5.7:使用RPM安装包方式(推荐)
https://mp.weixin.qq.com/s/40Z8P_pr745pmENa6zeBEw
CentOS7安装MySQL5.7:使用Yum存储库方式
https://mp.weixin.qq.com/s/nBkBxkYFhHSiyixDP9HWXA
CentOS 7安装mysql 5.7 (官网rpm方式)
https://blog.csdn.net/qq_32702685/article/details/122578635
Centos7 两种方式安装 MySQL5.7 步骤 yum 、本地 tar 文件
https://blog.csdn.net/agonie201218/article/details/135476981
源 MySQL 5.7 Community Server 的 GPG 密钥已安装,但是不适用于此软件包。请检查源的公钥 URL 是否配置正确。
https://blog.csdn.net/saindy5828/article/details/136190498
mysql之validate_password_policy
https://blog.csdn.net/wltsysterm/article/details/79649484
Centos7环境下修改MySql密码策略
https://blog.csdn.net/f_yuqing/article/details/118446658
MySQL数据库密码策略以及修改密码方式
https://blog.csdn.net/weixin_64341393/article/details/135282738
MySQL5.7和8.0版本修改用户名和密码教程
https://blog.csdn.net/tiansyun/article/details/132073689
[对比] MySQL5.7和MySQL8.0中修改密码的方式对比
https://blog.csdn.net/dber_ablewang/article/details/132606038
Mysql 8.0 使用mysql_native_password加密创建远程root用户
https://cloud.tencent.com/developer/article/1439706
【说站】MySQL8.0配置mysql_native_password方法教程
https://cloud.tencent.com/developer/article/2175351
linux下mysql 和 mysqld、service和systemctl区别
https://blog.csdn.net/weixin_46483006/article/details/125761575
MySQL 8 如何修改密码 —— 全面攻略 ?
https://cloud.tencent.com/developer/article/2404978
MySQL 5.7 与 8.0 分别修改用户密码
https://blog.csdn.net/lizhengyu891231/article/details/121969276
MySQL数据库密码策略以及修改密码方式
https://blog.csdn.net/weixin_64341393/article/details/135282738
########################################################################