溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

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

發(fā)布時間:2022-02-19 15:26:28 來源:億速云 閱讀:330 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要介紹“如何配置MySQL端口避免被占用”的相關(guā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.因為許多端口都有默認使用的情況,比如 3306 是 MySQL 的默認端口,如果 MySQL 不使用 3306 端口,其他需要進行數(shù)據(jù)庫交互的應(yīng)用需要重新配置(將其引導(dǎo)到正確的端口)。

解決方法

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

port 選項前的“#”去掉,然后等式后方填上端口號,保存完畢后。再次啟動數(shù)據(jù)庫就會使用新端口進行數(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)用都有默認端口,比如 MySQL使用 3306 端口,Tomcat 使用 80/8080 端口,不管是什么應(yīng)用,在配置的時候最好使用默認端口避免造成不必要的麻煩。MySQL 端口被占用的話正確的解決方式是將 3306 端口清理出來給 MySQL 使用。

關(guān)于“如何配置MySQL端口避免被占用”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識,可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點。

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI