- What Is MySQL Default Port Number?
- TCP 3306
- List with netstat Command
- Find From DB Config File
- Find By Nmap Scan
- Find with SQL Query
- Chapter 3 MySQL Port Reference Tables
- Client — Server Connection Ports
- MySQL Administrative Connection Port
- MySQL Shell Ports
- MySQL Workbench Ports
- MySQL Client — MySQL Router Connection Ports
- High Availability Ports
- External Authentication Ports
- Key Management Ports
- MySQL Enterprise Backup Ports
- Как проверить, на каком порту MySQL работает и может ли он быть подключен?
- 13 ответов
- Mysql server linux port
What Is MySQL Default Port Number?
MySQL is very popular database in the opensource community. While developing applications or connecting MySQL database we need to specify the MySQL port implicitly or explicitly. In this tutorial we will learn MySQL default port number and alternative port numbers.
TCP 3306
The default port for the MySQL service is TCP 3306. This port can be also used for MariaDB database server.
List with netstat Command
We can use netstat command in order to list MySQL/MariaDB database server port number.
List with netstat Command
We can see from output that port 3306 port is listening on the local interface 127.0.0.1
For MariaDB change grep mysql with grep mariadb
Find From DB Config File
What if MySQL server default port is different from 3306 . We have some options. One of them is looking to the application database config file. We can get the port number from there. In this example the port number 3307 is specified explicitly.
Find By Nmap Scan
If we had no clue about the port number we can use some security network scanning tool named nmap . We can scan popular or all port on the host and find MySQL service. Following command will scan top used 1000 ports.
OR we can scan all ports of the given host.
Find with SQL Query
Configuration parameter of the MySQL or MariaDB Database server is stored in the variables too. We can use some SQL inorder to print the port information from environment variables like below.
Find with SQL Query
We can see that port variable is current set to 3306 .
Источник
Chapter 3 MySQL Port Reference Tables
The following tables describe ports used by MySQL products and features. Port information is applicable to MySQL 5.7 and MySQL 8.0.
Client — Server Connection Ports
Port 3306 is the default port for the classic MySQL protocol ( port ), which is used by the mysql client, MySQL Connectors, and utilities such as mysqldump and mysqlpump . The port for X Protocol ( mysqlx_port ), supported by clients such as MySQL Shell, MySQL Connectors and MySQL Router, is calculated by multiplying the port used for classic MySQL protocol by 10. For example if the classic MySQL protocol port is the default value of 3306 then the X Protocol port is 33060.
Table 3.1 Client — Server Connection Ports
Default Port/Protocol | Description | SSL or other Encryption | Required | Direction |
---|---|---|---|---|
3306/TCP | MySQL clients to the MySQL server (classic MySQL protocol) | Yes | Yes, unless you are only using X Protocol | From the MySQL client to the MySQL server |
33060/TCP | MySQL clients to the MySQL server (X Protocol) | Yes | Yes, unless you are only using port 3306 | From the MySQL client to the MySQL server |
To verify the value of these ports on MySQL server, issue:
MySQL Administrative Connection Port
As of MySQL 8.0.14, the server permits a TCP/IP port to be configured specifically for administrative connections. This provides an alternative to the single administrative connection that is permitted on the network interfaces used for ordinary connections. For more information, see Administrative Connection Management.
Table 3.2 MySQL Administrative Connection Port
Default Port/Protocol | Description | SSL or other Encryption | Required | Direction |
---|---|---|---|---|
33062/TCP (default) | A port configured specifically for MySQL administrative connections (classic MySQL protocol) | Yes | No | From the MySQL client to the MySQL server |
To verify the value of this port on MySQL server, issue:
MySQL Shell Ports
MySQL Shell supports both X Protocol and classic MySQL protocol. For more information, see MySQL Shell 8.0.
Table 3.3 MySQL Shell Ports
Default Port/Protocol | Description | SSL or other Encryption | Required | Direction |
---|---|---|---|---|
3306/TCP | MySQL client to the MySQL server (classic MySQL protocol) | Yes | Yes, unless you are only using X Protocol | From MySQL Shell to the MySQL server |
33060/TCP | MySQL client to the MySQL server (X Protocol) | Yes | Yes, unless you are only using port 3306 | From MySQL Shell to the MySQL server |
33061/TCP | The port used by MySQL Shell to check a server during InnoDB Cluster configuration | Yes | Yes, if running InnoDB Cluster | From MySQL Shell to instances in an InnoDB Cluster |
MySQL Workbench Ports
Table 3.4 MySQL Workbench Ports
Default Port/Protocol | Description | SSL or other Encryption | Required | Direction |
---|---|---|---|---|
3306/TCP | MySQL client to the MySQL server (classic MySQL protocol) | Yes | Optional (use 3306, 33060, or 22) | From MySQL Workbench to the MySQL server |
22/TCP | Connection via SSH tunnel | Yes | Optional (use 3306, 33060, or 22) | From MySQL Workbench to the MySQL server |
MySQL Client — MySQL Router Connection Ports
Table 3.5 Client — Router Connection Ports
Default Port/Protocol | Description | SSL or other Encryption | Required | Direction |
---|---|---|---|---|
6446/TCP | Read-write SQL from the MySQL client to MySQL Router (classic MySQL protocol) | Yes. Inherited from the MySQL client and server. If the client —ssl-mode is VERIFY_IDENTITY , the router must reside at the same IP address as the server. | Required if MySQL Router provides read-write access | MySQL client read-write to MySQL Router |
6447/TCP | Read-only SQL from the MySQL client to MySQL Router (classic MySQL protocol) | Same as above | Required if MySQL Router provides read-only access | MySQL client read-only to MySQL Router |
6448/TCP | Read-write API calls from the MySQL client to MySQL Router (X Protocol) | Same as above | Required if MySQL Router provides read-write access | MySQL client to MySQL Router |
6449/TCP | Read-only calls from the MySQL client to MySQL Router (X Protocol) | Same as above | Required if MySQL Router provides read-only access | MySQL client to MySQL Router |
3306/TCP | MySQL Router to the MySQL server (classic MySQL protocol) | Same as above | Required | MySQL Router to the MySQL server |
33060/TCP | MySQL Router to the MySQL server (X Protocol) | Same as above | Required | MySQL Router to the MySQL server |
High Availability Ports
Table 3.6 High Availability Ports
Default Port/Protocol | Description | SSL or other Encryption | Required | Direction |
---|---|---|---|---|
33061/TCP | MySQL Group Replication internal communications port | Yes | Yes | Group Replication communication between group members (InnoDB Cluster instances) |
3306/TCP | MySQL Replication | Yes | Yes | Replica connection to the source |
External Authentication Ports
Table 3.7 External Authentication Ports
Default Port/Protocol | Description | SSL or other Encryption | Required | Direction |
---|---|---|---|---|
389/TCP | MySQL Enterprise Authentication (LDAP) | Yes | Only if using external authentication to LDAP. Also supports use of SASL | MySQL Enterprise Authentication in MySQL server to LDAP |
389/TCP | MySQL Enterprise Authentication (Active Directory) | Yes | Only if using external authentication to LDAP | MySQL Enterprise Authentication in MySQL server to Active Directory |
Key Management Ports
Key management ports are used for the MySQL Keyring features and Transparent Data Encryption (TDE).
Table 3.8 Key Management Ports
Default Port/Protocol | Description | SSL or other Encryption | Required | Direction |
---|---|---|---|---|
Varies. Refer to your key manager/vault documentation. | KMIP. Used with Oracle Key Vault, Gemalto KeySecure, Thales Vormetric key management server, and Fornetix Key Orchestration. | Yes | Only required if TDE uses a KMIP server | N/A |
443/TCP | Key Services — AWS Key Management Service (AWS KMS) | Yes | Only required if TDE uses AWS KMS | N/A |
MySQL Enterprise Backup Ports
Table 3.9 MySQL Enterprise Backup Ports
Источник
Как проверить, на каком порту MySQL работает и может ли он быть подключен?
Я установил MySQL и даже вошел туда как пользователь.
но когда я пытаюсь подключить так:
Не работает. Не уверен, что оба должны работать, но по крайней мере один из них должен 🙂
Как я могу убедиться, что порт действительно 3306? Есть ли команда linux, чтобы увидеть это как-то? Кроме того, есть ли более правильный способ попробовать его через url-адрес?
13 ответов
найти слушателя на порту, сделайте следующее:
вы должны увидеть строку, которая выглядит так, если mysql действительно слушает этот порт.
порт 3306 порт по умолчанию.
для подключения вам просто нужно использовать любой клиент, который вам нужен, например, базовый клиент mysql.
mysql-h localhost-U пользовательская база данных
или url-адрес, интерпретируемый кодом библиотеки.
использование mysql client:
grep port /etc/mysql/my.cnf (по крайней мере, в debian/ubuntu работает )
в /etc / mysql / my.КНФ, чтобы увидеть возможные ограничения
он покажет список что-то вроде ниже:
Используйте как root для всех деталей. The -t опция ограничивает выход TCP-соединениями, -l для прослушивания портов, -p содержит имя программы и -n показывает числовую версию порта вместо именованной версии.
таким образом, вы можете увидеть имя процесса и порт.
оба URL-адреса неверны-должно быть
Я думал, что это само собой разумеется, но для подключения к базе данных с Java требуется драйвер JDBC. Вам понадобится MySQL JDBC драйвер.
возможно, вы можете подключиться с помощью сокета через TCP / IP. Проверьте MySQL docs.
Я попытался telnet в MySQL ( telnet ip 3306 ), но это не работает:
Я думаю, что это то, что вы имели в виду.
попробуйте использовать только -e ( —execute ) параметр:
заменить root Ваш «логин» и «пароль»
более простой подход для некоторых : Если вы просто хотите проверить, если MySQL находится на определенном порте, вы можете использовать следующую команду в терминале. Протестировано на mac. По умолчанию используется порт 3306.
mysql —host=127.0.0.1 —port=3306
Если вы успешно вошли в терминал оболочки MySQL, вы хороши! Это результат, который я получаю при успешном входе в систему.
3306-порт по умолчанию для mysql. Проверьте это с:
он должен дать такой результат:
tcp 0 0 127.0.0.1:3306 0.0.0.0: * слушайте
для меня ответ @joseluisq дал:
ошибка 1045 (28000): доступ запрещен для пользователя «root» @ «localhost» (используя пароль: нет)
но это сработало так:
на mac os X есть два варианта. netstat или lsof
используя netstat не покажет процесс на Mac OS X. Поэтому с помощью netstat вы можете искать только по порту.
Используя lsof покажет имя процесса.
Я сделал следующее, когда столкнулся с конфликтами портов (контейнеры docker):
netstat -aln | grep 3306
выходы: tcp46 0 0 *.3306 *.* LISTEN
sudo lsof -i -P | grep -i «LISTEN» | grep -i 3306
выходы: mysqld 60608 _mysql 31u IPv6 0x2ebc4b8d88d9ec6b 0t0 TCP *:3306 (LISTEN)
Я согласен с решением @bortunac. мой.conf специфичен для mysql, в то время как netstat предоставит вам все порты прослушивания.
возможно, используйте оба, один, чтобы подтвердить, какой порт установлен для mysql, а другой, чтобы проверить, что система прослушивает через этот порт.
мой клиент использует CentOS 6.6, и я нашел my.conf файл под /etc/, поэтому я использовал:
grep port /etc/my.conf (CentOS 6.6)
если вы находитесь в системе, где netstat недоступен (например, RHEL 7 и более поздние выпуски Debian) вы можете использовать ss , как показано ниже:
и вы получите что-то вроде следующего вывода:
четвертая колонка — Local Address:Port . Таким образом, в этом случае Mysql прослушивает порт 3306, по умолчанию.
Источник
Mysql server linux port
This section describes use of command-line options to specify how to establish connections to the MySQL server, for clients such as mysql or mysqldump . For information on establishing connections using URI-like connection strings or key-value pairs, for clients such as MySQL Shell, see Section 4.2.5, “Connecting to the Server Using URI-Like Strings or Key-Value Pairs”. For additional information if you are unable to connect, see Section 6.2.21, “Troubleshooting Problems Connecting to MySQL”.
For a client program to connect to the MySQL server, it must use the proper connection parameters, such as the name of the host where the server is running and the user name and password of your MySQL account. Each connection parameter has a default value, but you can override default values as necessary using program options specified either on the command line or in an option file.
The examples here use the mysql client program, but the principles apply to other clients such as mysqldump , mysqladmin , or mysqlshow .
This command invokes mysql without specifying any explicit connection parameters:
Because there are no parameter options, the default values apply:
The default host name is localhost . On Unix, this has a special meaning, as described later.
The default user name is ODBC on Windows or your Unix login name on Unix.
No password is sent because neither —password nor -p is given.
For mysql , the first nonoption argument is taken as the name of the default database. Because there is no such argument, mysql selects no default database.
To specify the host name and user name explicitly, as well as a password, supply appropriate options on the command line. To select a default database, add a database-name argument. Examples:
For password options, the password value is optional:
If you use a —password or -p option and specify a password value, there must be no space between —password= or -p and the password following it.
If you use —password or -p but do not specify a password value, the client program prompts you to enter the password. The password is not displayed as you enter it. This is more secure than giving the password on the command line, which might enable other users on your system to see the password line by executing a command such as ps . See Section 6.1.2.1, “End-User Guidelines for Password Security”.
To explicitly specify that there is no password and that the client program should not prompt for one, use the —skip-password option.
As just mentioned, including the password value on the command line is a security risk. To avoid this risk, specify the —password or -p option without any following password value:
When the —password or -p option is given with no password value, the client program prints a prompt and waits for you to enter the password. (In these examples, mydb is not interpreted as a password because it is separated from the preceding password option by a space.)
On some systems, the library routine that MySQL uses to prompt for a password automatically limits the password to eight characters. That limitation is a property of the system library, not MySQL. Internally, MySQL does not have any limit for the length of the password. To work around the limitation on systems affected by it, specify your password in an option file (see Section 4.2.2.2, “Using Option Files”). Another workaround is to change your MySQL password to a value that has eight or fewer characters, but that has the disadvantage that shorter passwords tend to be less secure.
Client programs determine what type of connection to make as follows:
If the host is not specified or is localhost , a connection to the local host occurs:
On Windows, the client connects using shared memory, if the server was started with the shared_memory system variable enabled to support shared-memory connections.
On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs: the client connects using a Unix socket file. The —socket option or the MYSQL_UNIX_PORT environment variable may be used to specify the socket name.
On Windows, if host is . (period), or TCP/IP is not enabled and —socket is not specified or the host is empty, the client connects using a named pipe, if the server was started with the named_pipe system variable enabled to support named-pipe connections. If named-pipe connections are not supported or if the user making the connection is not a member of the Windows group specified by the named_pipe_full_access_group system variable, an error occurs.
Otherwise, the connection uses TCP/IP.
The —protocol option enables you to use a particular transport protocol even when other options normally result in use of a different protocol. That is, —protocol specifies the transport protocol explicitly and overrides the preceding rules, even for localhost .
Only connection options that are relevant to the selected transport protocol are used or checked. Other connection options are ignored. For example, with —host=localhost on Unix, the client attempts to connect to the local server using a Unix socket file, even if a —port or -P option is given to specify a TCP/IP port number.
To ensure that the client makes a TCP/IP connection to the local server, use —host or -h to specify a host name value of 127.0.0.1 (instead of localhost ), or the IP address or name of the local server. You can also specify the transport protocol explicitly, even for localhost , by using the —protocol=TCP option. Examples:
If the server is configured to accept IPv6 connections, clients can connect to the local server over IPv6 using —host=::1 . See Section 5.1.13, “IPv6 Support”.
On Windows, to force a MySQL client to use a named-pipe connection, specify the —pipe or —protocol=PIPE option, or specify . (period) as the host name. If the server was not started with the named_pipe system variable enabled to support named-pipe connections or if the user making the connection is not a member of the Windows group specified by the named_pipe_full_access_group system variable, an error occurs. Use the —socket option to specify the name of the pipe if you do not want to use the default pipe name.
Connections to remote servers use TCP/IP. This command connects to the server running on remote.example.com using the default port number (3306):
To specify a port number explicitly, use the —port or -P option:
You can specify a port number for connections to a local server, too. However, as indicated previously, connections to localhost on Unix use a socket file by default, so unless you force a TCP/IP connection as previously described, any option that specifies a port number is ignored.
For this command, the program uses a socket file on Unix and the —port option is ignored:
To cause the port number to be used, force a TCP/IP connection. For example, invoke the program in either of these ways:
For additional information about options that control how client programs establish connections to the server, see Section 4.2.3, “Command Options for Connecting to the Server”.
It is possible to specify connection parameters without entering them on the command line each time you invoke a client program:
Specify the connection parameters in the [client] section of an option file. The relevant section of the file might look like this:
Some connection parameters can be specified using environment variables. Examples:
To specify the host for mysql , use MYSQL_HOST .
On Windows, to specify the MySQL user name, use USER .
For a list of supported environment variables, see Section 4.9, “Environment Variables”.
Источник