Linux 本地启动mysql对应的3306端口也启动的情况下无法远程连接

1.运行netstat -talnp命令行看3306是否打开
netstat -talnp
如返回中有
tcp6 0 0 :::3306 :::* LISTEN 21498/mysqld
则证明3306已开启。
2.运行lsof -i:3306命令行查询3306是否被使用
lsof -i:3306
3.运行ps aux|grep mysql命令行看mysql是否在运行
ps aux|grep mysql

root 21353 0.0 0.1 9656 1560 pts/0 S 18:56 0:00 /bin/sh /opt/lampp/bin/mysqld_safe --datadir=/opt/lampp/var/mysql --pid-file=/opt/lampp/var/mysql/VM_42_114_centos.pid
mysql 21498 0.0 5.9 970100 60708 pts/0 Sl 18:56 0:00 /opt/lampp/sbin/mysqld --basedir=/opt/lampp --datadir=/opt/lampp/var/mysql --plugin-dir=/opt/lampp/lib/mysql/plugin/ --user=mysql --log-error=/opt/lam
pp/var/mysql/VM_42_114_centos.err --pid-file=/opt/lampp/var/mysql/VM_42_114_centos.pid --socket=/opt/lampp/var/mysql/mysql.sock --port=3306
root 23702 0.0 0.0 9032 672 pts/0 R+ 19:30 0:00 grep --color=auto mysql

即mysql服务在linux本地运行正常。

结论:mysql服务虽然在运行,可以在本地操作,但没有运行在3306端口。

此时修改mysql的配置文件如在xampp情况是在 ./lampp/etc my.cnf中

#Don’t listen on a TCP/IP port at all. This can be a security enhancement,
#if all processes that need to connect to mysqld run on the same host.
#All interaction with mysqld must be made via Unix sockets or named pipes.
#Note that using this option without enabling named pipes on Windows
#(via the “enable-named-pipe” option) will render mysqld useless!
将此段下面的参数skip-networking注释重启mysql服务,远程连接mysql正常。
#skip-networking
原因:参数skip-networking起的作用是:mysql不再在TCP / IP端口上进行监听,导致无法远程连接。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值