openEuler24.03 LTS下安装MySQL8.0.42
目录
前提步骤
删除原有mysql及maridb数据库
安装MySQL
启动MySQL
启动查看MySQL状态
设置MySQL开机自启动
查看登录密码
登录MySQL
修改密码及支持远程连接
远程连接MySQL
前提步骤
拥有openEuler24.03 LTS环境,可参考:Vmware下安装openEuler24.03 LTS
删除原有mysql及maridb数据库
如果原来有mysql或maridb数据库,请先备份数据,再进行删除操作。
$ sudo rpm -qa | grep -i 'mysql\|mariadb' | xargs -n1 sudo rpm -e --nodeps 2>/dev/null$ sudo rm -rf /var/lib/mysql* /var/log/mysql /usr/lib64/mysql /etc/my.cnf* /usr/my.cnf
操作过程如下
[liang@node1 ~]$ sudo rpm -qa | grep -i 'mysql\|mariadb' | xargs -n1 sudo rpm -e --nodeps 2>/dev/null
[liang@node1 ~]$ sudo rm -rf /var/lib/mysql* /var/log/mysql /usr/lib64/mysql /etc/my.cnf* /usr/my.cnf
安装MySQL
直接使用yum命令安装mysql服务
$ sudo yum install -y mysql-server
操作过程如下
[liang@node1 ~]$ sudo yum install -y mysql-server
OS 2.0 kB/s | 2.1 kB 00:01
everything 13 kB/s | 2.7 kB 00:00
EPOL 12 kB/s | 2.3 kB 00:00
debuginfo 10 kB/s | 2.2 kB 00:00
source 9.3 kB/s | 2.6 kB 00:00
update 8.0 kB/s | 2.2 kB 00:00
update-source 11 kB/s | 2.2 kB 00:00
Dependencies resolved.
====================================================================================Package Arch Version Repository Size
====================================================================================
Installing:mysql-server x86_64 8.0.42-1.oe2403sp1 update 32 M
Installing dependencies:abseil-cpp x86_64 20230802.1-6.oe2403sp1 update 508 kcheckpolicy x86_64 3.5-1.oe2403sp1 OS 293 kmecab x86_64 0.996-2.oe2403sp1 everything 375 kmysql x86_64 8.0.42-1.oe2403sp1 update 13 Mmysql-common x86_64 8.0.42-1.oe2403sp1 update 26 kmysql-config x86_64 8.0.42-1.oe2403sp1 update 6.5 kmysql-errmsg x86_64 8.0.42-1.oe2403sp1 update 574 kmysql-selinux noarch 1.0.10-1.oe2403sp1 everything 31 kpolicycoreutils-python-utils noarch 3.5-3.oe2403sp1 OS 22 kprotobuf-lite x86_64 25.1-7.oe2403sp1 OS 215 kpython3-IPy noarch 1.01-2.oe2403sp1 OS 44 kpython3-audit x86_64 1:3.1.2-7.oe2403sp1 OS 76 kpython3-libselinux x86_64 3.5-3.oe2403sp1 OS 174 kpython3-libsemanage x86_64 3.5-1.oe2403sp1 OS 71 kpython3-policycoreutils noarch 3.5-3.oe2403sp1 OS 2.2 Mpython3-setools x86_64 4.4.3-1.oe2403sp1 OS 657 kTransaction Summary
====================================================================================
Install 17 PackagesTotal download size: 51 M
Installed size: 263 M
Downloading Packages:
(1/17): policycoreutils-python-utils-3.5-3.oe2403sp 85 kB/s | 22 kB 00:00
(2/17): python3-IPy-1.01-2.oe2403sp1.noarch.rpm 382 kB/s | 44 kB 00:00
(3/17): checkpolicy-3.5-1.oe2403sp1.x86_64.rpm 715 kB/s | 293 kB 00:00
(4/17): protobuf-lite-25.1-7.oe2403sp1.x86_64.rpm 445 kB/s | 215 kB 00:00
(5/17): python3-libselinux-3.5-3.oe2403sp1.x86_64.r 2.0 MB/s | 174 kB 00:00
(6/17): python3-audit-3.1.2-7.oe2403sp1.x86_64.rpm 132 kB/s | 76 kB 00:00
(7/17): python3-libsemanage-3.5-1.oe2403sp1.x86_64. 102 kB/s | 71 kB 00:00
(8/17): mecab-0.996-2.oe2403sp1.x86_64.rpm 1.3 MB/s | 375 kB 00:00
(9/17): mysql-selinux-1.0.10-1.oe2403sp1.noarch.rpm 496 kB/s | 31 kB 00:00
(10/17): python3-policycoreutils-3.5-3.oe2403sp1.no 1.8 MB/s | 2.2 MB 00:01
(11/17): python3-setools-4.4.3-1.oe2403sp1.x86_64.r 765 kB/s | 657 kB 00:00
(12/17): mysql-common-8.0.42-1.oe2403sp1.x86_64.rpm 111 kB/s | 26 kB 00:00
(13/17): mysql-config-8.0.42-1.oe2403sp1.x86_64.rpm 120 kB/s | 6.5 kB 00:00
(14/17): abseil-cpp-20230802.1-6.oe2403sp1.x86_64.r 614 kB/s | 508 kB 00:00
(15/17): mysql-errmsg-8.0.42-1.oe2403sp1.x86_64.rpm 1.7 MB/s | 574 kB 00:00
(16/17): mysql-8.0.42-1.oe2403sp1.x86_64.rpm 963 kB/s | 13 MB 00:14
(17/17): mysql-server-8.0.42-1.oe2403sp1.x86_64.rpm 1.7 MB/s | 32 MB 00:19
------------------------------------------------------------------------------------
Total 2.3 MB/s | 51 MB 00:22
retrieving repo key for OS unencrypted from http://repo.openeuler.org/openEuler-24.03-LTS-SP1/OS/x86_64/RPM-GPG-KEY-openEuler
OS 4.9 kB/s | 3.0 kB 00:00
Importing GPG key 0xB675600B:Userid : "openeuler <openeuler@compass-ci.com>"Fingerprint: 8AA1 6BF9 F2CA 5244 010D CA96 3B47 7C60 B675 600BFrom : http://repo.openeuler.org/openEuler-24.03-LTS-SP1/OS/x86_64/RPM-GPG-KEY-openEuler
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transactionPreparing : 1/1Installing : python3-libselinux-3.5-3.oe2403sp1.x86_64 1/17Installing : mysql-config-8.0.42-1.oe2403sp1.x86_64 2/17Installing : mysql-common-8.0.42-1.oe2403sp1.x86_64 3/17Installing : abseil-cpp-20230802.1-6.oe2403sp1.x86_64 4/17Installing : protobuf-lite-25.1-7.oe2403sp1.x86_64 5/17Installing : mysql-8.0.42-1.oe2403sp1.x86_64 6/17Installing : mysql-errmsg-8.0.42-1.oe2403sp1.x86_64 7/17Installing : python3-libsemanage-3.5-1.oe2403sp1.x86_64 8/17Installing : python3-setools-4.4.3-1.oe2403sp1.x86_64 9/17Installing : mecab-0.996-2.oe2403sp1.x86_64 10/17Running scriptlet: mecab-0.996-2.oe2403sp1.x86_64 10/17Installing : python3-audit-1:3.1.2-7.oe2403sp1.x86_64 11/17Installing : python3-IPy-1.01-2.oe2403sp1.noarch 12/17Running scriptlet: checkpolicy-3.5-1.oe2403sp1.x86_64 13/17Installing : checkpolicy-3.5-1.oe2403sp1.x86_64 13/17Running scriptlet: checkpolicy-3.5-1.oe2403sp1.x86_64 13/17Installing : python3-policycoreutils-3.5-3.oe2403sp1.noarch 14/17Installing : policycoreutils-python-utils-3.5-3.oe2403sp1.noarch 15/17Running scriptlet: mysql-selinux-1.0.10-1.oe2403sp1.noarch 16/17Installing : mysql-selinux-1.0.10-1.oe2403sp1.noarch 16/17Running scriptlet: mysql-selinux-1.0.10-1.oe2403sp1.noarch 16/17
libsemanage.semanage_direct_install_info: Overriding mysql module at lower priority 100 with module at priority 200.Running scriptlet: mysql-server-8.0.42-1.oe2403sp1.x86_64 17/17Installing : mysql-server-8.0.42-1.oe2403sp1.x86_64 17/17Running scriptlet: mysql-server-8.0.42-1.oe2403sp1.x86_64 17/17Running scriptlet: mysql-selinux-1.0.10-1.oe2403sp1.noarch 17/17Running scriptlet: mysql-server-8.0.42-1.oe2403sp1.x86_64 17/17
/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.Verifying : checkpolicy-3.5-1.oe2403sp1.x86_64 1/17Verifying : policycoreutils-python-utils-3.5-3.oe2403sp1.noarch 2/17Verifying : protobuf-lite-25.1-7.oe2403sp1.x86_64 3/17Verifying : python3-IPy-1.01-2.oe2403sp1.noarch 4/17Verifying : python3-audit-1:3.1.2-7.oe2403sp1.x86_64 5/17Verifying : python3-libselinux-3.5-3.oe2403sp1.x86_64 6/17Verifying : python3-libsemanage-3.5-1.oe2403sp1.x86_64 7/17Verifying : python3-policycoreutils-3.5-3.oe2403sp1.noarch 8/17Verifying : python3-setools-4.4.3-1.oe2403sp1.x86_64 9/17Verifying : mecab-0.996-2.oe2403sp1.x86_64 10/17Verifying : mysql-selinux-1.0.10-1.oe2403sp1.noarch 11/17Verifying : abseil-cpp-20230802.1-6.oe2403sp1.x86_64 12/17Verifying : mysql-8.0.42-1.oe2403sp1.x86_64 13/17Verifying : mysql-common-8.0.42-1.oe2403sp1.x86_64 14/17Verifying : mysql-config-8.0.42-1.oe2403sp1.x86_64 15/17Verifying : mysql-errmsg-8.0.42-1.oe2403sp1.x86_64 16/17Verifying : mysql-server-8.0.42-1.oe2403sp1.x86_64 17/17Installed:abseil-cpp-20230802.1-6.oe2403sp1.x86_64checkpolicy-3.5-1.oe2403sp1.x86_64mecab-0.996-2.oe2403sp1.x86_64mysql-8.0.42-1.oe2403sp1.x86_64mysql-common-8.0.42-1.oe2403sp1.x86_64mysql-config-8.0.42-1.oe2403sp1.x86_64mysql-errmsg-8.0.42-1.oe2403sp1.x86_64mysql-selinux-1.0.10-1.oe2403sp1.noarchmysql-server-8.0.42-1.oe2403sp1.x86_64policycoreutils-python-utils-3.5-3.oe2403sp1.noarchprotobuf-lite-25.1-7.oe2403sp1.x86_64python3-IPy-1.01-2.oe2403sp1.noarchpython3-audit-1:3.1.2-7.oe2403sp1.x86_64python3-libselinux-3.5-3.oe2403sp1.x86_64python3-libsemanage-3.5-1.oe2403sp1.x86_64python3-policycoreutils-3.5-3.oe2403sp1.noarchpython3-setools-4.4.3-1.oe2403sp1.x86_64Complete!
启动MySQL
$ sudo systemctl start mysqld
启动查看MySQL状态
[liang@node1 ~]$ sudo systemctl status mysqld
● mysqld.service - MySQL 8.0 database serverLoaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; preset: disa>Active: active (running) since Wed 2025-05-07 22:59:59 CST; 3min 7s agoProcess: 2811 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status>Process: 2834 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (co>Main PID: 2912 (mysqld)Status: "Server is operational"Tasks: 37 (limit: 21353)Memory: 473.3M ()CGroup: /system.slice/mysqld.service└─2912 /usr/libexec/mysqld --basedir=/usr5月 07 22:59:54 node1 systemd[1]: Starting MySQL 8.0 database server...
5月 07 22:59:55 node1 mysql-prepare-db-dir[2834]: Initializing MySQL database
5月 07 22:59:59 node1 systemd[1]: Started MySQL 8.0 database server.
lines 1-15/15 (END)
看到Active: active (running)
,说明mysql服务正常启动。
按q
键返回命令行。
设置MySQL开机自启动
[liang@node1 ~]$ sudo systemctl enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
查看登录密码
[liang@node1 ~]$ sudo cat /var/log/mysql/mysqld.log
2025-05-07T14:59:55.041414Z 0 [System] [MY-013169] [Server] /usr/libexec/mysqld (mysqld 8.0.42) initializing of server in progress as process 2869
2025-05-07T14:59:55.046791Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-05-07T14:59:55.301970Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-05-07T14:59:55.986953Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2025-05-07T14:59:58.680076Z 0 [System] [MY-010116] [Server] /usr/libexec/mysqld (mysqld 8.0.42) starting as process 2912
2025-05-07T14:59:58.689207Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2025-05-07T14:59:59.073809Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2025-05-07T14:59:59.317924Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2025-05-07T14:59:59.317946Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2025-05-07T14:59:59.340722Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/lib/mysql/mysqlx.sock
2025-05-07T14:59:59.340759Z 0 [System] [MY-010931] [Server] /usr/libexec/mysqld: ready for connections. Version: '8.0.42' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution.
输出看到[Server] root@localhost is created with an empty password !
,说明初始密码为空。
登录MySQL
$ mysql -uroot -p
提示输入密码,因为是空密码,不需要输入任何信息直接回车,进入mysql命令行。
操作过程如下
[liang@node1 ~]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.42 Source distributionCopyright (c) 2000, 2025, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)mysql> quit;
Bye
[liang@node1 ~]$
修改密码及支持远程连接
mysql> set password='000000';
mysql> update mysql.user set host='%' where user='root';
mysql> flush privileges;
操作过程如下
[liang@node1 ~]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.42 Source distributionCopyright (c) 2000, 2025, 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> set password='000000';
Query OK, 0 rows affected (0.01 sec)mysql> update mysql.user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)mysql> quit;
Bye
[liang@node1 ~]$
使用新密码登录
[liang@node1 ~]$ 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 10
Server version: 8.0.42 Source distributionCopyright (c) 2000, 2025, 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
使用navicat等工具远程连接mysql
完成!enjoy it!