mysql: error while loading shared libraries: libcrypto.so.3

mysql: error while loading shared libraries: libcrypto.so.3

𝓓𝓸𝓷 Lv6

在遇到 MySQL 8报错 “error while loading shared libraries: libcrypto.so.3” 时,通常是因为系统找不到所需的 libcrypto.so.3 库文件,libcrypto.so.3 是 OpenSSL 3.0 中的一个库文件,MySQL 8.x 版本和一些 MariaDB 版本可能依赖这个库。

一、错误提示

1
2
[root@server01 ~]# mysql -uroot -p
mysql: error while loading shared libraries: libcrypto.so.3: cannot open shared object file: No such file or directory

二、验证 MySQL 是否能正确加载 OpenSSL 库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@server01 backup]# ldd $(which mysqld)
linux-vdso.so.1 => (0x00007ffe60ffe000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fd6fb3f2000)
libcrypto.so.3 => not found
libssl.so.3 => not found
librt.so.1 => /lib64/librt.so.1 (0x00007fd6fb1ea000)
libprotobuf-lite.so.3.19.4 => not found
libaio.so.1 => /lib64/libaio.so.1 (0x00007fd6fafe8000)
libnuma.so.1 => /lib64/libnuma.so.1 (0x00007fd6faddc000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fd6fabd8000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fd6fa8d0000)
libm.so.6 => /lib64/libm.so.6 (0x00007fd6fa5ce000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fd6fa3b8000)
libc.so.6 => /lib64/libc.so.6 (0x00007fd6f9fea000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd6fb60e000)

三、查看当前系统是否已存在libcrypto.so.3库文件

1
2
3
[root@server01 ~]# find / -name "libcrypto.so.3"
/usr/local/lib64/libcrypto.so.3
/usr/local/mysql/lib/private/libcrypto.so.3

四、添加LD_LIBRARY_PATH环境

1
2
3
4
5
[root@server01 ~]# vi /etc/profile
export LD_LIBRARY_PATH=/usr/local/mysql/lib/private:$LD_LIBRARY_PATH


[root@server01 ~]# source /etc/profile

五、重新验证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@server01 ~]# ldd $(which mysqld)
linux-vdso.so.1 => (0x00007ffc2e9c5000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f9c0ddb6000)
libcrypto.so.3 => /usr/local/mysql/lib/private/libcrypto.so.3 (0x00007f9c0d785000)
libssl.so.3 => /usr/local/mysql/lib/private/libssl.so.3 (0x00007f9c0d4df000)
librt.so.1 => /lib64/librt.so.1 (0x00007f9c0d2d7000)
libprotobuf-lite.so.3.19.4 => /usr/local/mysql/lib/private/libprotobuf-lite.so.3.19.4 (0x00007f9c0e14c000)
libaio.so.1 => /lib64/libaio.so.1 (0x00007f9c0d0d5000)
libnuma.so.1 => /lib64/libnuma.so.1 (0x00007f9c0cec9000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f9c0ccc5000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f9c0c9bd000)
libm.so.6 => /lib64/libm.so.6 (0x00007f9c0c6bb000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f9c0c4a5000)
libc.so.6 => /lib64/libc.so.6 (0x00007f9c0c0d7000)
/lib64/ld-linux-x86-64.so.2 (0x00007f9c0dfd2000)

六、登录Mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@server01 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 227605
Server version: 8.0.34 MySQL Community Server - GPL

Copyright (c) 2000, 2023, 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正确路径或添加PATH环境变量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@server01 ~]# which mysql
/usr/bin/mysql

[root@server01 ~]# ps -ef|grep mysql|grep basedir
mysql 1558 1247 4 2024 ? 6-22:47:51 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/apps/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/apps/mysql/mysql.log --pid-file=/apps/data/server01.pid --socket=/tmp/mysql.sock --port=3306

[root@server01 ~]# /usr/local/mysql/bin/mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

[root@server01 ~]# vi /etc/profile
export PATH=/usr/local/mysql/bin:$PATH

[root@server01 ~]# source /etc/profile
  • Title: mysql: error while loading shared libraries: libcrypto.so.3
  • Author: 𝓓𝓸𝓷
  • Created at : 2025-01-15 16:08:09
  • Updated at : 2025-01-15 16:44:06
  • Link: https://www.zhangdong.me/mysql-error-libcrypto.html
  • License: This work is licensed under CC BY-NC-SA 4.0.
评论