当前位置: 首页 > news >正文

openEuler24.03 LTS下安装MySQL8

前提条件

拥有openEuler24.03 LTS环境,可参考:Vmware下安装openEuler24.03 LTS

步骤

卸载原有mysql及mariadb

sudo systemctl stop mysql mysqld 2>/dev/null
sudo rpm -qa | grep -i 'mysql\|mariadb' | xargs -n1 sudo rpm -e --nodeps 2>/dev/null
sudo rm -rf /var/lib/mysql /var/log/mysqld.log /usr/lib64/mysql /etc/my.cnf /usr/my.cnf

下载mysql

这里下载的mysql版本为mysql8.4.2,如果下载较旧的mysql版本可能与openEuler24.03不兼容。

cd /opt/software
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.4.2-1.el9.x86_64.rpm-bundle.tar

注意:如果命令行下载较慢,可以直接使用浏览器访问https链接地址下载,再上传安装文件到Linux的安装包存放目录,例如:/opt/software。

解压mysql

# 创建mysql目录
[liang@node1 software]$ mkdir mysql

#解压
[liang@node1 software]$ tar -xvf mysql-8.4.2-1.el9.x86_64.rpm-bundle.tar -C mysql

删除不必要的rpm包

[liang@node1 software]$ cd mysql
[liang@node1 mysql]$ rm -f *debug*
[liang@node1 mysql]$ ls
mysql-community-client-8.4.2-1.el9.x86_64.rpm          mysql-community-libs-8.4.2-1.el9.x86_64.rpm
mysql-community-client-plugins-8.4.2-1.el9.x86_64.rpm  mysql-community-libs-compat-8.4.2-1.el9.x86_64.rpm
mysql-community-common-8.4.2-1.el9.x86_64.rpm          mysql-community-server-8.4.2-1.el9.x86_64.rpm
mysql-community-devel-8.4.2-1.el9.x86_64.rpm           mysql-community-test-8.4.2-1.el9.x86_64.rpm
mysql-community-icu-data-files-8.4.2-1.el9.x86_64.rpm

安装mysql

[liang@node1 mysql]$ sudo rpm -ivh *.rpm --force --nodeps

安装过程

[liang@node1 mysql]$ sudo rpm -ivh *.rpm --force --nodeps
警告:mysql-community-client-8.4.2-1.el9.x86_64.rpm: 头 V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-common-8.4.2-1.el################################# [ 11%]
   2:mysql-community-client-plugins-8.################################# [ 22%]
   3:mysql-community-libs-8.4.2-1.el9 ################################# [ 33%]
   4:mysql-community-client-8.4.2-1.el################################# [ 44%]
   5:mysql-community-icu-data-files-8.################################# [ 56%]
   6:mysql-community-server-8.4.2-1.el################################# [ 67%]
   7:mysql-community-test-8.4.2-1.el9 ################################# [ 78%]
   8:mysql-community-devel-8.4.2-1.el9################################# [ 89%]
   9:mysql-community-libs-compat-8.4.2################################# [100%]
/usr/lib/tmpfiles.d/dbus.conf:13: Line references path below legacy directory /var/run/, updating /var/run/dbus/containers → /run/dbus/containers; please update the tmpfiles.d/ drop-in file accordingly.
[liang@node1 mysql]$

启动mysql服务

[liang@node1 mysql]$ sudo systemctl start mysqld

开机自启动mysql服务

[liang@node1 mysql]$ sudo systemctl enable mysqld

登录mysql

查看临时密码 

[liang@node1 mysql]$ sudo grep 'temporary password' /var/log/mysqld.log

输出如下

2025-03-10T14:00:35.282869Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Rh8f67o%F,v>

这里查看到的临时密码为:Rh8f67o%F,v>

注意:查看到的临时密码可能不一样,请使用实际查到的临时密码登录mysql。

登录mysql

[liang@node1 mysql]$ mysql -uroot -p'Rh8f67o%F,v>'
[liang@node1 mysql]$ mysql -uroot -p'Rh8f67o%F,v>'
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: 8.4.2
​
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
​
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密码

修改密码策略

若在内网环境使用MySQL,想使用设置简单密码,则需要设置密码策略,否则,不需要设置密码策略。

[liang@node1 mysql]$ sudo vim /etc/my.cnf

在[mysqld]下面添加如下语句

validate_password.length=4
validate_password.policy=0

重启mysql

[liang@node1 mysql]$ sudo systemctl restart mysqld

 登录mysql并修改密码

[liang@node1 mysql]$ mysql -uroot -p'Rh8f67o%F,v>'

mysql> set password='000000';
Query OK, 0 rows affected (0.00 sec)

mysql> update mysql.user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> alter user 'root'@'%' identified by '000000';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

使用新密码登录

[liang@node1 mysql]$ mysql -uroot -p000000
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 9
Server version: 8.4.2 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

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> exit;
Bye
[liang@node1 mysql]$

远程连接mysql

使用navicat等工具,通过ip及端口号远程连接

完成!enjoy it!

相关文章:

  • dfs(十二)21. 合并两个有序链表 递归解决
  • Spring 框架中常用注解和使用方法
  • 如何管理需求变更
  • 做游戏的发展方向
  • Skyeye 云智能制造办公系统 VUE 版本 v3.15.13 发布
  • ChatGPT and Claude国内使用站点
  • CareUEyes护眼软件深度解析:为你的双眼保驾护航
  • 基于Gemini 生成 Gemini Embedding
  • 学习笔记之注册用户如何防止缓存穿透
  • 365天之第P10周:Pytorch实现车牌识别
  • OceanBase 4.3.3 AP 功能解析:物化视图
  • 嵌入式开发之STM32学习笔记day06
  • C语言:编程设计猜数游戏
  • 【Dify平台】Function Call 模式模式和ReAct模型有什么不同?
  • 大数据技术链路详解
  • 什么是数学建模?数学建模是将实际问题转化为数学问题
  • C++学习笔记(二十一)——文件读写
  • 蓝桥杯 阶乘约数
  • 使用matlab求伴随矩阵
  • 图像处理篇:图像预处理——从数据到模型的桥梁
  • 短剧迷|《权宠》一出,《名不虚传》
  • 李在明回应韩国大法院判决:与自己所想截然不同,将顺从民意
  • 奥斯卡新规:评委必须看完影片再投票;网友:以前不是啊?
  • 澎湃读报丨央媒头版集中刊发社论,庆祝“五一”国际劳动节
  • 光明日报社论:用你我的匠心,托举起繁盛的中国
  • 航海王亚洲巡展、工厂店直销……上海多区推出“五五购物节”活动