python定制脚本安装mysql socket文件存在无法连接

自己定制一个python脚本可以一键安装mysql实例,

遇到mysql socket文件已经创建成功但是无法通过socket文件进行连接

报错原因

python 复制代码
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/storage/mysql3310/mysql3310.sock' (2)

程序需要停歇几秒通过socket连接才能成功

通过观察日志socket文件生成日期比较早

powershell 复制代码
2024-10-17 15:59:40,953 - ssh_client - WARNING - will exit host
ssh 192.168.56.102 ps -ef|grep mysql|grep 3310
0 root      8705     1  0 15:59 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my3310.cnf
root      8989  8705  0 15:59 ?        00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my3310.cnf --basedir=/usr/local/mysql --datadir=/storage/mysql3310 --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=error.log --pid-file=mysql02.pid --socket=/storage/mysql3310/mysql3310.sock --port=3310
ssh 192.168.56.102 ps -ef|grep mysql|grep 3310|wc -l
2024-10-17 15:59:41,338 - __main__ - INFO - mysql 3310 is started,next step is reset root password

mysql启动日志中显示可以连接时间比较晚

powershell 复制代码
2024-10-17T15:59:41.349054+08:00 0 [Warning] [MY-011068] [Server] The syntax 'expire-logs-days' is deprecated and will be remo
ved in a future release. Please use binlog_expire_logs_seconds instead.
2024-10-17T15:59:41.349145+08:00 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.22) starting as proce
ss 8989
2024-10-17T15:59:41.355519+08:00 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-10-17T15:59:41.899082+08:00 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-10-17T15:59:42.049942+08:00 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 3306
0, socket: /tmp/mysqlx.sock
2024-10-17T15:59:42.291311+08:00 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2024-10-17T15:59:42.291481+08:00 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted conne
ctions are now supported for this channel.
2024-10-17T15:59:42.313666+08:00 0 [System] [MY-010931] [Server] /usr/local/mysql/bin/mysqld: ready for connections. Version: 
'8.0.22'  socket: '/storage/mysql3310/mysql3310.sock'  port: 3310  MySQL Community Server - GPL.

所以mysql启动之后如果通过程序立即连接是可能出现通过socket无法连接情况出现

相关推荐
YMLT花岗岩1 分钟前
Python学习之-函数-入门训练-具有多个返回值的函数
python·学习
北鹤M1 分钟前
用MeteoStat计算任意时刻经纬度真实气象数据
人工智能·python
星瞳科技OpenMV5 分钟前
星瞳OpenMV官方机械臂教程|从零开始:Robot Arm机械臂快速上手
arm开发·图像处理·python·计算机视觉·ai·机器人·openmv
写代码的【黑咖啡】22 分钟前
Python中的lxml:高效XML处理库
xml·开发语言·python
人工智能AI技术34 分钟前
【Agent从入门到实践】29 开发第一个Agent——需求定义
人工智能·python
理智.6291 小时前
Cursor 中使用 Conda 虚拟环境常见问题与彻底解决方案(踩坑实录)
python·conda
aiguangyuan1 小时前
中文分词与文本分析实战指南
人工智能·python·nlp
小二·1 小时前
Python Web 开发进阶实战:量子机器学习实验平台 —— 在 Flask + Vue 中集成 Qiskit 构建混合量子-经典 AI 应用
前端·人工智能·python
one____dream2 小时前
【网安】pwn-ret2shellcode
python·安全·网络安全·网络攻击模型
给你一页白纸2 小时前
将分散的Pytest测试脚本统一接入测试平台:FastAPI改造方案详解
python·pytest·接口自动化·测试平台