本文目錄一覽:
linux系統如何查找mysql所在端口
my.ini(Linux系統下是my.cnf),當mysql服務器啟動時它會讀取這個文件,設置相關的運行環境參數。
此文件中有一個參數是 port;
port = 3306 # 設置mysql客戶端連接服務端時默認使用的端口
找到mysql運行目錄下的my.ini(Linux系統下是my.cnf),查看此參數即可。
linux下怎麼查看數據庫端口
如何查看mysql 默認端口號和修改端口號
1. 登錄mysql
[root@test /]# mysql -u root -p
Enter password:
2. 使用命令show global variables like ‘port’;查看端口號
mysql show global variables like ‘port’;
+—————+——-+
| Variable_name | Value |
+—————+——-+
| port | 3306 |
+—————+——-+
1 row in set (0.00 sec)
3. 修改端口,編輯/etc/my.cnf文件,早期版本有可能是my.conf文件名,增加端口參數,並且設定端口,注意該端口未被使用,保存退出。
[root@test etc]# vi my.cnf
[mysqld]
port=3506
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
“my.cnf” 11L, 261C written
[root@test etc]#
4. 重新啟動mysql
[root@test ~]# /etc/init.d/mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
5.再次登錄後檢查端口已修改為’3506’.
[root@test etc]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.66 Source distribution
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql show global variables like ‘port’;
+—————+——-+
| Variable_name | Value |
+—————+——-+
| port | 3506 |
+—————+——-+
1 row in set (0.00 sec)
mysql
總結:注意修改的端口不要被佔用,而且要有規劃,不要輕意的總是調整數據庫端口。還有就是安全保障,記得與負責網絡的人提前通知,以免端口無法正常使用。
linux怎麼查看mysql的端口
my.ini(Linux系統下是my.cnf),當mysql服務器啟動時它會讀取這個文件,設置相關的運行環境參數。
此文件中有一個參數是 port;
port = 3306 # 設置mysql客戶端連接服務端時默認使用的端口
找到mysql運行目錄下的my.ini(Linux系統下是my.cnf),查看此參數即可。
mysql怎麼查看端口號,和服務名
mysql的默認端口號是3306,通常mysql的服務名都是mysqld.
mysql是否啟動可以用netstat
-lntp
|
grep
3306
,
也可以用ps
ax|grep
mysqld的方式查看,
還可以去mysql的配置文件(my.cnf)里查看。
希望我的回答對你有幫助
linux如何查看端口
x使用過程中,需要了解當前系統開放了哪些端口,並且要查看開放這些端口的具體進程和用戶,可以通過netstat命令進行簡單查詢
netstat命令各個參數說明如下:
-t : 指明顯示TCP端口
-u : 指明顯示UDP端口
-l : 僅顯示監聽套接字(所謂套接字就是使應用程序能夠讀寫與收發通訊協議(protocol)與資料的程序)
-p : 顯示進程標識符和程序名稱,每一個套接字/端口都屬於一個程序。
-n : 不進行DNS輪詢,顯示IP(可以加速操作)
即可顯示當前服務器上所有端口及進程服務,於grep結合可查看某個具體端口及服務情況··
netstat -ntlp //查看當前所有tcp端口·
netstat -ntulp |grep 80 //查看所有80端口使用情況·
netstat -ntulp | grep 3306 //查看所有3306端口使用情況·
Linux查看程序端口佔用情況
使用命令:
ps -aux | grep tomcat
發現並沒有8080端口的Tomcat進程。
使用命令:netstat –apn
查看所有的進程和端口使用情況。發現下面的進程列表,其中最後一欄是PID/Program name
發現8080端口被PID為9658的Java進程佔用。
進一步使用命令:ps -aux | grep java,或者直接:ps -aux | grep pid 查看
就可以明確知道8080端口是被哪個程序佔用了!然後判斷是否使用KILL命令幹掉!
方法二:直接使用 netstat -anp | grep portno
即:netstat -anp|grep 8080
netstat -anp|grep 8080 — tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 28500/java
ps -aux | grep 28500 — r/local/tomcat9-jforum/tomcat
安裝lsof list open files//—也可以 netstat -tunlp|grep 端口號 netstat -anp|grep 端口號
yum install lsof
lsof -i:8080 查看8080端口佔用
lsof abc.txt 顯示開啟文件abc.txt的進程
lsof -c abc 顯示abc進程現在打開的文件
lsof -c -p 1234 列出進程號為1234的進程所打開的文件
lsof -g gid 顯示歸屬gid的進程情況
lsof +d /usr/local/ 顯示目錄下被進程開啟的文件
lsof +D /usr/local/ 同上,但是會搜索目錄下的目錄,時間較長
lsof -d 4 顯示使用fd為4的進程
lsof -i 用以顯示符合條件的進程情況
lsof -i[46] [protocol][@hostname|hostaddr][:service|port]
46 — IPv4 or IPv6
protocol — TCP or UDP
hostname — Internet host name
hostaddr — IPv4地址
service — /etc/service中的 service name (可以不止一個)
port — 端口號 (可以不止一個)
lsof -i //顯示所有打開的端口
lsof -i:80 //顯示所有打開80端口的進程
lsof -i -U //顯示所有打開的端口和UNIX domain文件
其實我一般這樣用:
[root@VM_39_230_centos bin]# lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 16422 mysql 19u IPv6 148794 0t0 TCP *:mysql (LISTEN)
mysqld 16422 mysql 39u IPv6 643698 0t0 TCP localhost:mysql-localhost:36582 (ESTABLISHED)
mysqld 16422 mysql 45u IPv6 643699 0t0 TCP localhost:mysql-localhost:36584 (ESTABLISHED)
mysql
原創文章,作者:TOCA,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/131525.html