Mysql远程连接访问的问题处理
今天在升级阿里云服务器MySQL从 5.5到5.7版本时,升级成功后,不能远程访问了,只能在服务器终端访问,折腾了一下午,原来是MySQL配置
my.cnf
里边的[mysqld] bind-address=127.0.0.1
限制的问题,注释掉就可以了一、事故现场
使用PHP
<?php // 1.连接数据库 $db_host ="121.29.19.5:3306"; $db_user = "root"; $db_pass = "ali_123456"; $conn = mysql_connect($db_host, $db_user, $db_pass); if (!$conn) { die("Could not connect:" . mysql_error()); }else { dump("连接成功!"); }
错误抛出:
Could not connect:Lost connection to MySQL server at 'reading initial communication packet', system error: 111
什么原因呢?后来在网上找了一圈,原来是MySQL配置bind-address
限制的问题。
MySQL配置修改
先找到 my.conf
配置文件
find / -name my.conf
cat my.cnf !includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/
最终找到[mysqld]
在mysql.conf.d
文件夹中:
注释掉即可:bind-address=127.0.0.1
[mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql log-error = /var/log/mysql/error.log # By default we only accept connections from localhost #bind-address = 127.0.0.1 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0
相关推荐
CoderToy 2020-11-16
emmm00 2020-11-17
王艺强 2020-11-17
ribavnu 2020-11-16
bianruifeng 2020-11-16
wangshuangbao 2020-11-13
苏康申 2020-11-13
vivenwan 2020-11-13
moyekongling 2020-11-13
云中舞步 2020-11-12
要啥自行车一把梭 2020-11-12
aydh 2020-11-12
kuwoyinlehe 2020-11-12
minerk 2020-11-12
vitasfly 2020-11-12
jazywoo在路上 2020-11-11
敏敏张 2020-11-11
世樹 2020-11-11