前提条件
拥有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: 0mysql> 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 - GPLCopyright (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!