先下载压缩包,下载地址:MySQL : 下载 MySQL Community Server (存档版本)https://downloads.mysql.com/archives/community/
卸载旧版本的MySql (没有的话,则跳过此步骤)
1、查看旧版本MySql
[root@localhost ~]# rpm -qa | grep mysql 查看旧版本MySql
[root@localhost ~]# ls
anaconda-ks.cfg mysql-community-server-5.7.36-1.el7.x86_64.rpm
[root@localhost ~]# rm -rf mysql-community-server-5.7.36-1.el7.x86_64.rpm删除
[root@localhost ~]# ls
anaconda-ks.cfg
[root@localhost ~]# rpm -qa | grep mairadb查看旧版本mairadb
[root@localhost ~]# ls
anaconda-ks.cfg
[root@localhost ~]# rz 上传压缩包
[root@localhost ~]# ls
anaconda-ks.cfg mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar
[root@localhost ~]# tar xf mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar解压压缩包
[root@localhost ~]# ls
anaconda-ks.cfg mysql-community-embedded-compat-5.7.25-1.el7.x86_64.rpm
mysql mysql-community-embedded-devel-5.7.25-1.el7.x86_64.rpm
mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar mysql-community-libs-5.7.25-1.el7.x86_64.rpm
mysql-community-client-5.7.25-1.el7.x86_64.rpm mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm
mysql-community-common-5.7.25-1.el7.x86_64.rpm mysql-community-server-5.7.25-1.el7.x86_64.rpm
mysql-community-devel-5.7.25-1.el7.x86_64.rpm mysql-community-test-5.7.25-1.el7.x86_64.rpm
mysql-community-embedded-5.7.25-1.el7.x86_64.rpm
安装一下顺序安装,否则会有报错
[root@localhost ~]# rpm -ivh mysql-community-common-5.7.25-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.25-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.25-1.e################################# [100%]
[root@localhost ~]# rpm -ivh mysql-community-libs-5.7.25-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.25-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-5.7.25-1.el7################################# [100%]
[root@localhost ~]# rpm -ivh mysql-community-client-5.7.25-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.25-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-5.7.25-1.e################################# [100%]
[root@localhost ~]# rpm -ivh mysql-community-server-5.7.25-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.25-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-server-5.7.25-1.e################################# [100%]
[root@localhost ~]# systemctl start mysqld.service 启动MySQL
[root@localhost ~]# systemctl status mysqld.service 查看MySQL状态
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 二 2023-04-04 20:58:31 CST; 11s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 1299 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 1226 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 1303 (mysqld)
CGroup: /system.slice/mysqld.service
└─1303 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
4月 04 20:58:25 localhost.localdomain systemd[1]: Starting MySQL Server...
4月 04 20:58:31 localhost.localdomain systemd[1]: Started MySQL Server.
[root@localhost ~]# systemctl enable mysqld.service 设置开机自启
[root@localhost ~]# ps -ef|grep mysql 查看MySQL进程
mysql 1367 1 0 20:59 ? 00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root 1416 928 0 20:59 pts/0 00:00:00 grep --color=auto mysql
[root@localhost ~]# netstat -anop|grep 3306查看端口号
tcp6 0 0 :::3306 :::* LISTEN 1367/mysqld off (0.00/0/0)
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log获取临时密码
2023-04-04T12:58:26.890176Z 1 [Note] A temporary password is generated for root@localhost: =CZEoqieb8/w
[root@localhost ~]# mysqladmin -uroot -p'=CZEoqieb8/w' password 'FanLi@123'修改密码
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@localhost ~]# mysql -uroot -p'FanLi@123'登录MySQL
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.25 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
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>
mysql> exit输入exit退出
Bye