前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MySQL-8.0.32 启动失败问题的分析

MySQL-8.0.32 启动失败问题的分析

作者头像
初代庄主
发布2023-04-20 19:08:41
1.7K0
发布2023-04-20 19:08:41
举报
文章被收录于专栏:初代庄主

背景

朋友安装了一个 MySQL-8.0.32 版本的 MySQL;其中服务端可以正常运行但是客户端运行不了。

1.1 ps 检查发现 mysqld 确实运行起来了。

代码语言:javascript
复制
ps -ef | grep mysql
mysql33+  407393       1  0 16:00 ?        00:00:03 /usr/local/mysql-8.0.32-linux-glibc2.12-x86_64/bin/mysqld --defaults-file=/etc/my-3306.cnf
root      412577  407779  0 16:21 pts/13   00:00:00 grep --color=auto mysql

1.2 mysql 客户端命令无法运行。

代码语言:javascript
复制
mysql -uroot -pxxxxxx -h127.0.0.1 -P3306
mysql: error while loading shared libraries: libtinfo.so.5: 
cannot open shared object file: No such file or directory

分析

从报错的信息来看就是在加载 libtinfo.so.5 这个共享库的时候失败了。作为一个 cpper 遇到这个问题我还是比较淡定的,因为问题通常只有两个 1. 系统上有这个库文件但是它没有找到,2. 系统上根本就没有这个库文件。

对于情况 1 我们只要想办法让 mysql 能找到对应的库就行了,对于情况 2 我们只要安装上对应的依赖就能解决。

那么剩下的就是分析一下是什么情况了。先补充一下理论,加载库文件本质上就是打开库文件,对应的是 read 这个系统调用,也就是说我们只要追踪一下系统调用就可以分析出来

2.1 strace 分析系统调用

代码语言:javascript
复制
strace mysql -uroot -pxxxxxx -h127.0.0.1 -e "exit;"

2.2 通过输出可以看到进程去如下地方找了 libtinfo.so.5

代码语言:javascript
复制
openat(AT_FDCWD, "/usr/local/mysql-8.0.32-linux-glibc2.12-x86_64/bin/../lib/private/libtinfo.so.5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/glibc-hwcaps/x86-64-v3/libtinfo.so.5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/glibc-hwcaps/x86-64-v2/libtinfo.so.5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/tls/x86_64/x86_64/libtinfo.so.5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/tls/x86_64/libtinfo.so.5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/tls/x86_64/libtinfo.so.5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/tls/libtinfo.so.5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/x86_64/x86_64/libtinfo.so.5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/x86_64/libtinfo.so.5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/x86_64/libtinfo.so.5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib64/libtinfo.so.5", O_RDONLY|O_CLOEXEC) = 3

进程去了两 “类” 地方找了 libtinfo.so.5 这个库;第一类是 MySQL 的安装目录,第二类是系统默认的库路径。

2.3 确认 libtinfo.so.5 是不是 MySQL 安装包里的库

代码语言:javascript
复制
tree /usr/local/mysql-8.0.32-linux-glibc2.12-x86_64/lib | grep libtinfo

在 MySQL 的 lib 目录下找不到,说明这个不是 MySQL 自带的库。

2.4 确认是不是系统库

代码语言:javascript
复制
tree /lib64/ | grep libtinfo
├── libtinfo.so -> libtinfo.so.6
├── libtinfo.so.6 -> libtinfo.so.6.2
├── libtinfo.so.6.2

可以看得出两个结论 1. libtinfo 是系统库;2. 系统上的 libtinfo 库的版本已经升级到了 libtinfo.so.6 。程序找 libtinfo.so.5 所以会找不到。

难道是他的操作系统太新了?我确认一下。

代码语言:javascript
复制
cat /etc/system-release
CentOS Stream release 9

系统都到 CentOS-9 了确实新!



解决办法

通过前面的分析可以看到由于系统比较新,libtinfo.so 的版本已经升级到 6 了,然而 mysql 还依赖于 5 。/lib64 下面的是基础库,如果采用降级的方式来处理影响面就太大了;最终选择 “骗” 一下 MySQL ,告诉它有一个 libtinfo.so.5 但是实际上是 libtinfo.so.6 。

代码语言:javascript
复制
# 创建 5 版本的连接文件
cd /lib64
ln -s libtinfo.so libtinfo.so.5
# 重启加载库
ldconfig

检查

代码语言:javascript
复制
mysql -uroot -pxxxxxx -h127.0.0.1 -P3306
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 22
Server version: 8.0.32 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> select @@version;
+-----------+
| @@version |
+-----------+
| 8.0.32    |
+-----------+
1 row in set (0.00 sec)

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-04-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 初代庄主 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 MySQL
腾讯云数据库 MySQL(TencentDB for MySQL)为用户提供安全可靠,性能卓越、易于维护的企业级云数据库服务。其具备6大企业级特性,包括企业级定制内核、企业级高可用、企业级高可靠、企业级安全、企业级扩展以及企业级智能运维。通过使用腾讯云数据库 MySQL,可实现分钟级别的数据库部署、弹性扩展以及全自动化的运维管理,不仅经济实惠,而且稳定可靠,易于运维。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档