简体   繁体   English

如何识别SQL服务器的端口号

[英]How to Identify port number of SQL server

I Install SQL server in my system and I have to check on which port number SQL is working in my system我在我的系统中安装了 SQL 服务器,我必须检查哪个端口号 SQL 在我的系统中工作

  1. Open SQL Server Management Studio打开 SQL Server 管理工作室
  2. Connect to the database engine for which you need the port number连接到需要端口号的数据库引擎
  3. Run the below query against the database对数据库运行以下查询

    select distinct local_net_address, local_tcp_port from sys.dm_exec_connections where local_net_address is not null

The above query shows the local IP as well as the listening Port number上面的查询显示了本地 IP 以及侦听端口号

  1. Open Run in your system.在您的系统中打开运行。

  2. Type %windir%\\System32\\cliconfg.exe输入%windir%\\System32\\cliconfg.exe

  3. Click on ok button then check that the "TCP/IP Network Protocol Default Value Setup" pop-up is open.单击确定按钮,然后检查“TCP/IP 网络协议默认值设置”弹出窗口是否打开。

  4. Highlight TCP/IP under the Enabled protocols window.在启用的协议窗口下突出显示 TCP/IP。

  5. Click the Properties button.单击属性按钮。

  6. Enter the new port number, then click OK.输入新的端口号,然后单击“确定”。

在此处输入图片说明

You can also use this query您也可以使用此查询

USE MASTER GO xp_readerrorlog 0, 1, N'Server is listening on' GO

Source : sqlauthority blog来源: sqlauthority 博客

Visually you can open "SQL Server Configuration Manager" and check properties of "Network Configuration":您可以直观地打开“SQL Server 配置管理器”并检查“网络配置”的属性:

SQL 服务器配置

This query works for me:这个查询对我有用:

SELECT DISTINCT 
    local_tcp_port 
FROM sys.dm_exec_connections 
WHERE local_tcp_port IS NOT NULL 

要检查在所有端口上侦听的所有应用程序,请使用以下命令:

netstat -ntpl

PowerShell solution that shows all of the instances on the host as well as their incoming traffic addresses. PowerShell 解决方案,显示主机上的所有实例及其传入流量地址。 The second bit might be helpful if all you know is the DNS:如果您只知道 DNS,第二位可能会有所帮助:

ForEach ($SQL_Proc in Get-Process | Select-Object -Property ProcessName, Id | Where-Object {$_.ProcessName -like "*SQL*"})
{
    Get-NetTCPConnection | `
     Where-Object {$_.OwningProcess -eq $SQL_Proc.id} | `
      Select-Object -Property `
                                @{Label ="Process_Name";e={$SQL_Proc.ProcessName}}, `
                                @{Label ="Local_Address";e={$_.LocalAddress + ":" + $_.LocalPort }},  `
                                @{Label ="Remote_Address";e={$_.RemoteAddress + ":" + $_.RemotePort}}, State | `
      Format-Table
} 

if you are able to login in just use如果您能够登录,请使用

select @@port;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM