80端口被MySQL占用怎么办?MySQL端口如何配置?

猿友 2021-05-26 16:16:02 浏览数 (4122)
反馈

在使用 MySQL 的时候,有时候会出现 MySQL 占用别的端口的情况(比如 MySQL 占用80端口)有时候会出现 MySQL 的端口被占用的情况。一旦端口被占用,出现一些问题。接下来就让小编告诉你会出现哪些问题,以及如何配置 MySQL 端口避免占用吧。

端口占用带来的问题

1.MySQL 占用了其他应用的端口,导致其他应用无法运行(比如 Tomcat 使用80端口,MySQL 占用了该端口后 Tomcat 就无法启动)。

2.MySQL 端口被其他应用占用,导致 MySQL 无法运行(比如某应用占用了 MySQL 的 3306 端口,MySQL 就无法启动了)。

3.因为许多端口都有默认使用的情况,比如 3306 是 MySQL 的默认端口,如果 MySQL 不使用 3306 端口,其他需要进行数据库交互的应用需要重新配置(将其引导到正确的端口)。

解决方法

MySQL 的端口是可以设置的,在 ​my.ini​(​my-default.ini​ )中可以设置(该文件位于数据库文件夹下,高版本的 MySQL 没有这样一个默认的配置文件,但创建一个这样的配置文件也可生效)。

my.ini配置

将 ​port​ 选项前的“#”去掉,然后等式后方填上端口号,保存完毕后。再次启动数据库就会使用新端口进行数据库的交互了。

附:​my.ini​ 文件内容:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

注意事项

许多的应用都有默认端口,比如 MySQL使用 3306 端口,Tomcat 使用 80/8080 端口,不管是什么应用,在配置的时候最好使用默认端口避免造成不必要的麻烦。MySQL 端口被占用的话正确的解决方式是将 3306 端口清理出来给 MySQL 使用。

小结

以上就是 MySQL 端口配置的全部内容了。更多软件配置问题,上W3C技术头条寻找答案。


SQL

0 人点赞