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无法连接情况出现

相关推荐
协皓家具11 分钟前
2026年广州岛台吧台椅厂家有啥新变化
大数据·运维·python·devops
yuniko-n19 分钟前
【Java】字符串相关坑点
java·开发语言·python
用户0190275816122 分钟前
如何用 Python 统计 A 股连续涨停(几连板)?
python
外收内放24 分钟前
Python基础语法练习题(拓展1)
python·游戏
H_unique1 小时前
Chat2Excel:接口自动化测试
python·测试工具·自动化
ss2731 小时前
AI全栈实战 | 3.3-02 Python 并发:有 GIL 为什么还用多线程,asyncio 和 JS 事件循环同源不同味
开发语言·javascript·python
空心木偶☜1 小时前
Langgraph操作时常见的错误
python·ai·ai编程·langgraph
cpolar技术支持1 小时前
外网测试机的异常传不回内网?自托管 Sentry,用 cpolar 打通错误上报链路
python·nginx·docker·cpolar·sentry
小小龙学IT1 小时前
Python SQLAlchemy 2.0 深度解析:从 Core 到 ORM 的数据访问双引擎
开发语言·数据库·python
2601_962885721 小时前
如何用 Python 计算 ROC 变动率指标做动量分析?
开发语言·python·算法