你的浏览器不支持canvas

做你害怕做的事情,然后你会发现,不过如此。

Linux离线安装MySQL8.0.34

时间: 作者: 黄运鑫

本文章属原创文章,未经作者许可,禁止转载,复制,下载,以及用作商业用途。原作者保留所有解释权。


下载MySql

  • 系统版本CentOS Linux 7
  • 下载安装包:https://dev.mysql.com/downloads/mysql
    • Select Version:选择MySQL版本8.0.34
    • Select 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 '新密码';重置默认密码,安装完成

对于本文内容有问题或建议的小伙伴,欢迎在文章底部留言交流讨论。