今天尝试从linux下安装Mysql数据库,需要远程测试时发现3306端口无法被远程机器访问。一开始以为是linux防火墙对于3306端口做了限制,但是关闭防火墙后发现也无法进行telnet。
经查询相关资料发现,mysql默认对于本地连接做了绑定,如果需要远程机器访问,则需要修改相关规则
具体如下
1.找到如下文件
/etc/mysql/mysql.conf.d/mysqld.cnf
2.打开该文件,显示
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[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
3.找到 bind-address 项
注释该项或者添加指定访问远程机
# bind-address = 127.0.0.1
bind-address=127.0.0.1 xx.xx.xx.xx