如何配置MySQL端口避免被占用

网友投稿 709 2023-07-04

如何配置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 没有这样一个默认的配置文件,但创建一个这样的配置文件也可生效)。

将 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 使用。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:MySQL中LAG()函数和LEAD()函数如何使用
下一篇:Linux系统如何重启MySQL
相关文章