下载MySql
- 系统版本
CentOS Linux 7
- 下载安装包:https://dev.mysql.com/downloads/mysql
Select Version
:选择MySQL版本8.0.34Select Operating System
:选择Red Hat Enterprise Linux / Oracle Linux
Select OS Version
:根据实际的系统和处理器架构选择
卸载旧版
- 如果之前安装过旧版,需要先卸载旧版,此方法仅适用于rpm方式安装的mysql
- 执行
systemctl stop mysqld
停止mysql服务 - 执行
rpm -qa | grep mysql
查看rpm方式安装的mysql,结果如下
[root@ngd-app1 ~]# rpm -qa | grep mysql
mysql-community-libs-5.7.37-1.el7.x86_64
mysql-community-embedded-5.7.37-1.el7.x86_64
mysql-community-embedded-compat-5.7.37-1.el7.x86_64
mysql-community-common-5.7.37-1.el7.x86_64
mysql-community-client-5.7.37-1.el7.x86_64
mysql-community-devel-5.7.37-1.el7.x86_64
mysql-community-embedded-devel-5.7.37-1.el7.x86_64
mysql-community-libs-compat-5.7.37-1.el7.x86_64
mysql-community-server-5.7.37-1.el7.x86_64
mysql-community-test-5.7.37-1.el7.x86_64
- 执行
rpm -ev --nodeps 组件名称
卸载,卸载后再执行rpm -qa | grep mysql
结果为空说明已经卸载 - 执行
find / -name mysql
查找mysql文件夹,再执行rm -rf 文件夹
删除查找到的文件夹 - 执行
whereis mysql
,结果为空则删除完成
安装
- 将下载的安装包
mysql-8.0.34-1.el7.x86_64.rpm-bundle.tar
上传到服务器/usr/local/mysql
目录下,没有目录先执行mkdir /usr/local/mysql
创建目录 - 执行
cd /usr/local/mysql
进入目录 - 执行
tar -xvf mysql-8.0.34-1.el7.x86_64.rpm-bundle.tar
解压安装包 - 执行
rpm -ivh *.rpm --force --nodeps
安装刚才解压后的文件--force --nodeps
的作用是不检查依赖关系和强制安装,结果如下:
[root@ngd-app1 mysql]# rpm -ivh *.rpm --force --nodeps
warning: mysql-community-client-8.0.34-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-8.0.34-1.e################################# [ 8%]
2:mysql-community-client-plugins-8.################################# [ 17%]
3:mysql-community-libs-8.0.34-1.el7################################# [ 25%]
4:mysql-community-client-8.0.34-1.e################################# [ 33%]
5:mysql-community-icu-data-files-8.################################# [ 42%]
6:mysql-community-server-8.0.34-1.ewarning: /etc/my.cnf created as /etc/my.cnf.rpmnew
################################# [ 50%]
7:mysql-community-server-debug-8.0.################################# [ 58%]
8:mysql-community-test-8.0.34-1.el7################################# [ 67%]
9:mysql-community-devel-8.0.34-1.el################################# [ 75%]
10:mysql-community-libs-compat-8.0.3################################# [ 83%]
11:mysql-community-embedded-compat-8################################# [ 92%]
12:mysql-community-debuginfo-8.0.34-################################# [100%]
- 执行
rpm -qa | grep mysql
验证是否安装,结果如下:
[root@ngd-app1 mysql]# rpm -qa | grep mysql
mysql-community-client-8.0.34-1.el7.x86_64
mysql-community-test-8.0.34-1.el7.x86_64
mysql-community-debuginfo-8.0.34-1.el7.x86_64
mysql-community-common-8.0.34-1.el7.x86_64
mysql-community-libs-8.0.34-1.el7.x86_64
mysql-community-icu-data-files-8.0.34-1.el7.x86_64
mysql-community-server-debug-8.0.34-1.el7.x86_64
mysql-community-devel-8.0.34-1.el7.x86_64
mysql-community-embedded-compat-8.0.34-1.el7.x86_64
mysql-community-client-plugins-8.0.34-1.el7.x86_64
mysql-community-server-8.0.34-1.el7.x86_64
mysql-community-libs-compat-8.0.34-1.el7.x86_64
启动
- 执行
systemctl start mysqld
启动mysql
- 执行
systemctl enable mysqld
添加到开机启动 - 执行
systemctl status mysqld
查看启动状态,已启动结果如下:
[root@ngd-app1 mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2023-09-11 11:40:54 CST; 11s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 24821 (mysqld)
Status: "Server is operational"
CGroup: /system.slice/mysqld.service
└─24821 /usr/sbin/mysqld
Sep 11 11:39:55 ngd-app1 systemd[1]: Starting MySQL Server...
Sep 11 11:40:54 ngd-app1 systemd[1]: Started MySQL Server.
登录
- 执行
cat /var/log/mysqld.log | grep password
查看默认密码,结果如下:
[root@ngd-app1 mysql]# cat /var/log/mysqld.log | grep password
2023-09-11T09:49:53.604593Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: k6-tjirsek1G
- 执行
mysql -uroot -p
,然后输入刚才的默认密码登录mysql
- 登录后执行
ALTER USER USER() IDENTIFIED BY '新密码';
重置默认密码,安装完成