MySQL 启动失败:Can‘t connect to local MySQL server through socket ‘/usr/local/mysql/data/mysql.sock‘

在CentOS7上源码安装完MySQL8.0.31后,遇到启动失败的问题,错误提示显示端口3307已被占用。通过检查mysqld.log日志,发现InnoDB初始化过程中存在错误,同时确认有其他进程占用了该端口。解决方法是使用lsof命令找出占用端口的进程ID,然后使用kill命令结束该进程,从而释放端口,成功启动MySQL服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CentOS7 使用源码安装完 MySQL8.0.31 后,出现启动失败问题!!!

 问题说明:

  mysql 安装完成后,一般可使用如下命令启动 mysql;

bin/mysqld_safe --user=mysql &

  正常情况下输入启动命令后,再输入如下命令及初始密码,即可进入mysql;

bin/mysql -uroot -p   #执行该命令后出入初始密码,进入mysql

  但是今天我在执行 mysql 启动命令后,出现如下提示:

2023-07-31T08:17:42.131276Z mysqld_safe mysqld from pid file /usr/local/mysql/data/mysqld.pid ended

说明:上述意思大概是说,mysql 服务已停止;所以后面即使再输入:bin/mysql -uroot -p初始密码也无法进入 mysql ,且会提示如下错误!

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/usr/local/mysql/data/mysql.sock'

 于是乎!!!

我查看了 MySQL 安装目录下的 mysqld.log (我的目录为:/usr/local/mysql/data/)日志,日志内容如下:

2023-07-31T08:06:55.802016Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2023-07-31T08:06:55.802126Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.31) initializing of serv in progress as process 20348
2023-07-31T08:06:55.810198Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-07-31T08:06:56.695475Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-07-31T08:06:58.639754Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: >alonj%-Z4j*
[root@vm10-0-0-236 data]# cat mysqld.log 
2023-07-31T08:06:55.802016Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2023-07-31T08:06:55.802126Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.31) initializing of serv in progress as process 20348
2023-07-31T08:06:55.810198Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-07-31T08:06:56.695475Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-07-31T08:06:58.639754Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: >alonj%-Z4j*
2023-07-31T08:07:23.268585Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2023-07-31T08:07:23.268698Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.31) starting as process 584
2023-07-31T08:07:23.276568Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-07-31T08:07:23.343831Z 1 [ERROR] [MY-012562] [InnoDB] We scanned the log up to 19325952. A checkpoint was at 19325996 a the maximum LSN on a database page was 0. It is possible that the database is now corrupt!
2023-07-31T08:07:23.343866Z 1 [Warning] [MY-013412] [InnoDB] The last block of redo had corrupted first_rec_group and becameixed (0 -> 44).
2023-07-31T08:07:23.536217Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-07-31T08:07:24.624559Z 0 [ERROR] [MY-011292] [Server] Plugin mysqlx reported: 'Preparation of I/O interfaces failed, X otocol won't be accessible'
2023-07-31T08:07:24.624590Z 0 [ERROR] [MY-011300] [Server] Plugin mysqlx reported: 'Setup of bind-address: '*' port: 33060 fled, `bind()` failed with error: Address already in use (98). Do you already have another mysqld server running with Mysqlx 
2023-07-31T08:07:24.624597Z 0 [ERROR] [MY-013597] [Server] Plugin mysqlx reported: 'Value '*' set to `Mysqlx_bind_address`, Plugin can't bind to it. Skipping this value.'
2023-07-31T08:07:24.624606Z 0 [ERROR] [MY-011300] [Server] Plugin mysqlx reported: 'Setup of socket: '/tmp/mysqlx.sock' fail, another process with PID 20155 is using UNIX socket file'
2023-07-31T08:07:24.771731Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-07-31T08:07:24.771770Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connectis are now supported for this channel.
2023-07-31T08:07:24.771954Z 0 [ERROR] [MY-010262] [Server] Can't start server: Bind on TCP/IP port: Address already in use
2023-07-31T08:07:24.771961Z 0 [ERROR] [MY-010257] [Server] Do you already have another mysqld server running on port: 3307 ?
2023-07-31T08:07:24.771972Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-07-31T08:07:25.802572Z 0 [System] [MY-010910] [Server] /usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.31)  urce distribution.
2023-07-31T08:07:47.681777Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2023-07-31T08:07:47.681887Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.31) starting as process 816
2023-07-31T08:07:47.688141Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-07-31T08:07:47.847692Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-07-31T08:07:48.938404Z 0 [ERROR] [MY-011292] [Server] Plugin mysqlx reported: 'Preparation of I/O interfaces failed, X otocol won't be accessible'
2023-07-31T08:07:48.938441Z 0 [ERROR] [MY-011300] [Server] Plugin mysqlx reported: 'Setup of bind-address: '*' port: 33060 fled, `bind()` failed with error: Address already in use (98). Do you already have another mysqld server running with Mysqlx 
2023-07-31T08:07:48.938453Z 0 [ERROR] [MY-013597] [Server] Plugin mysqlx reported: 'Value '*' set to `Mysqlx_bind_address`, Plugin can't bind to it. Skipping this value.'
2023-07-31T08:07:48.938471Z 0 [ERROR] [MY-011300] [Server] Plugin mysqlx reported: 'Setup of socket: '/tmp/mysqlx.sock' fail, another process with PID 20155 is using UNIX socket file'
2023-07-31T08:07:49.039721Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-07-31T08:07:49.039752Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connectis are now supported for this channel.
2023-07-31T08:07:49.039916Z 0 [ERROR] [MY-010262] [Server] Can't start server: Bind on TCP/IP port: Address already in use
2023-07-31T08:07:49.039923Z 0 [ERROR] [MY-010257] [Server] Do you already have another mysqld server running on port: 3307 ?
2023-07-31T08:07:49.039935Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-07-31T08:07:50.108334Z 0 [System] [MY-010910] [Server] /usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.31)  urce distribution.

 其中有一行内容如下:

2023-07-31T08:07:49.039923Z 0 [ERROR] [MY-010257] [Server] Do you already have another mysqld server running on port: 3307 ?

说明:该行大概意思是说,目前的端口已被占用(我在配置用指定端口号为:3307;不指定时,默认为:3306);

 解决方案:

 找到端口号对应的进程 id ,杀死该进程,释放端口号即可!

执行如下命令( 3307 为我的 mysql 端口号),查看端口号对应的进程 id;

lsof -i:3307

执行结果如下所示: 

执行如下命令杀死该进程: 

kill -9 20155

 

 释放被占用的端口号,前面所述问题也将随之解决!!!

问题解决后 MySQL 启动结果:

 

 

### 错误分析 错误 `ERROR 2002 (HY000): Can't connect to local MySQL server through socket` 表明客户端无法通过指定的套接字文件与本地 MySQL 服务器建立连接[^1]。 常见的原因可能包括: - MySQL 服务未启动- 套接字路径配置不正确。 - 文件权限设置不当,导致访问被拒绝。 ### 解决方案 #### 验证 MySQL 服务状态 确认 MySQL 服务是否正在运行。可以使用以下命令来检查服务状态: ```bash sudo systemctl status mysql ``` 如果服务未启动,则尝试启动它: ```bash sudo systemctl start mysql ``` #### 检查套接字文件位置 默认情况下,MySQL 使用 `/var/lib/mysql/mysql.sock` 或其他特定路径作为套接字文件的位置。可以通过查看 MySQL 配置文件 (`my.cnf`) 来验证实际使用的套接字路径: ```bash cat /etc/my.cnf | grep socket ``` 确保 `[client]` 和 `[mysqld]` 节中的 `socket` 参数指向相同的路径。 #### 修改套接字路径 如果发现配置文件中的路径有误,编辑该文件并更正路径。例如,在 `/etc/my.cnf` 中添加或修改如下行: ```ini [client] socket=/usr/local/mysql/data/mysql.sock [mysqld] socket=/usr/local/mysql/data/mysql.sock ``` 保存更改后重启 MySQL 服务使新配置生效。 #### 设置正确的文件权限 确保套接字目录及其父级具有适当的所有权和读写权限。通常应由 `mysql:mysql` 用户组拥有这些资源: ```bash chown -R mysql:mysql /usr/local/mysql/data/ chmod 755 /usr/local/mysql/data/ ``` 完成以上操作之后再次测试数据库连接情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

数据库内核

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值