App下載

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

猿友 2021-05-26 16:16:02 瀏覽數(shù) (4934)
反饋

在使用 MySQL 的時候,有時候會出現(xiàn) MySQL 占用別的端口的情況(比如 MySQL 占用80端口)有時候會出現(xiàn) MySQL 的端口被占用的情況。一旦端口被占用,出現(xiàn)一些問題。接下來就讓小編告訴你會出現(xiàn)哪些問題,以及如何配置 MySQL 端口避免占用吧。

端口占用帶來的問題

1.MySQL 占用了其他應(yīng)用的端口,導(dǎo)致其他應(yīng)用無法運行(比如 Tomcat 使用80端口,MySQL 占用了該端口后 Tomcat 就無法啟動)。

2.MySQL 端口被其他應(yīng)用占用,導(dǎo)致 MySQL 無法運行(比如某應(yīng)用占用了 MySQL 的 3306 端口,MySQL 就無法啟動了)。

3.因為許多端口都有默認(rèn)使用的情況,比如 3306 是 MySQL 的默認(rèn)端口,如果 MySQL 不使用 3306 端口,其他需要進(jìn)行數(shù)據(jù)庫交互的應(yīng)用需要重新配置(將其引導(dǎo)到正確的端口)。

解決方法

MySQL 的端口是可以設(shè)置的,在 ?my.ini?(?my-default.ini? )中可以設(shè)置(該文件位于數(shù)據(jù)庫文件夾下,高版本的 MySQL 沒有這樣一個默認(rèn)的配置文件,但創(chuàng)建一個這樣的配置文件也可生效)。

my.ini配置

將 ?port? 選項前的“#”去掉,然后等式后方填上端口號,保存完畢后。再次啟動數(shù)據(jù)庫就會使用新端口進(jìn)行數(shù)據(jù)庫的交互了。

附:?my.ini? 文件內(nèi)容:

# 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 

注意事項

許多的應(yīng)用都有默認(rèn)端口,比如 MySQL使用 3306 端口,Tomcat 使用 80/8080 端口,不管是什么應(yīng)用,在配置的時候最好使用默認(rèn)端口避免造成不必要的麻煩。MySQL 端口被占用的話正確的解決方式是將 3306 端口清理出來給 MySQL 使用。

小結(jié)

以上就是 MySQL 端口配置的全部內(nèi)容了。更多軟件配置問題,上W3C技術(shù)頭條尋找答案。


SQL

0 人點贊