MySQL8.0連接協(xié)議及3306、33060、33062端口的作用解析
一、MySQL連接層
連接層為每個(gè)連接維護(hù)一個(gè)線程。該線程處理查詢執(zhí)行。 在連接可以開(kāi)始發(fā)送 SQL 查詢之前,連接由驗(yàn)證用戶名、密碼和客戶端主機(jī)。
連接層通過(guò)多種連接協(xié)議接受來(lái)自應(yīng)用程序的連接:
- TCP/IP
- UNIX 套接字
- 共享內(nèi)存
- 命名管道
如下圖所示:
二、連接協(xié)議
協(xié)議在客戶端庫(kù)和驅(qū)動(dòng)程序中實(shí)現(xiàn)。
連接協(xié)議的速度因本地設(shè)置而異。
除了舊版 MySQL 經(jīng)典協(xié)議之外,MySQL X 協(xié)議還引入了MySQL 5.7.12 并在 MySQL 8.0 中默認(rèn)啟用。
MySQL 使用 TCP 將消息從客戶端通過(guò)網(wǎng)絡(luò)傳輸?shù)椒?wù)器,可以使用以 mysqlx 為前綴的變量和選項(xiàng)來(lái)配置 MySQL X 協(xié)議。
mysqlx 變量的一些示例:
- • mysqlx
- • mysqlx_bind_address
- • mysqlx_max_connections
- • mysqlx_port
- • mysqlx_socket
三、本地和遠(yuǎn)程連接協(xié)議:TCP/IP
TCP/IP(傳輸控制協(xié)議/互聯(lián)網(wǎng)協(xié)議):
1、是用于連接 Internet 上的主機(jī)的連接協(xié)議套件
2、使用 IP 地址或 DNS 主機(jī)名來(lái)識(shí)別主機(jī)
3、使用 TCP 端口號(hào)來(lái)標(biāo)識(shí)每個(gè)主機(jī)上的特定服務(wù)
MySQL 默認(rèn) TCP 端口號(hào):
1、3306 用于 MySQL Classic 協(xié)議(服務(wù)器端口選項(xiàng))
2、33060 用于 MySQL X 協(xié)議(服務(wù)器 mysqlx_port 選項(xiàng))
3、33062 用于使用 MySQL Classic 協(xié)議的管理連接(服務(wù)器 admin_port 選項(xiàng))
修改my.cnf
admin_address='localhost'
修改前后對(duì)比:
[root@hadoop1 ~]# mysql -e "show variables like 'admin%'"; +------------------------+-----------------+ | Variable_name | Value | +------------------------+-----------------+ | admin_address | | | admin_port | 33062 | | admin_ssl_ca | | | admin_ssl_capath | | | admin_ssl_cert | | | admin_ssl_cipher | | | admin_ssl_crl | | | admin_ssl_crlpath | | | admin_ssl_key | | | admin_tls_ciphersuites | | | admin_tls_version | TLSv1.2,TLSv1.3 | +------------------------+-----------------+ [root@hadoop1 ~]# systemctl restart mysqld.service [root@hadoop1 ~]# mysql -e "show variables like 'admin%'"; +------------------------+-----------------+ | Variable_name | Value | +------------------------+-----------------+ | admin_address | localhost | | admin_port | 33062 | | admin_ssl_ca | | | admin_ssl_capath | | | admin_ssl_cert | | | admin_ssl_cipher | | | admin_ssl_crl | | | admin_ssl_crlpath | | | admin_ssl_key | | | admin_tls_ciphersuites | | | admin_tls_version | TLSv1.2,TLSv1.3 | +------------------------+-----------------+ [root@hadoop1 ~]#
成功登錄:
[root@hadoop1 ~]# mysql -P 33062 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 17 Server version: 8.0.28 MySQL Community Server - GPL Copyright (c) 2000, 2022, Oracle and/or its affiliates. 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>
網(wǎng)絡(luò)監(jiān)聽(tīng)情況:
[root@hadoop1 ~]# netstat -anltp | grep 33062 tcp 0 0 127.0.0.1:33062 0.0.0.0:* LISTEN 1104641/mysqld [root@hadoop1 ~]#
設(shè)置最大連接數(shù)方便測(cè)試:
mysql> set global max_connections = 1; Query OK, 0 rows affected (0.00 sec)
重新連接:
[root@hadoop1 ~]# mysql ERROR 1040 (HY000): Too many connections [root@hadoop1 ~]# mysql -P 33062 --protocol tcp Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 21 Server version: 8.0.28 MySQL Community Server - GPL Copyright (c) 2000, 2022, Oracle and/or its affiliates. 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>
從 MySQL 8.0.14 開(kāi)始,MySQL 服務(wù)器允許專門為管理連接配置 TCP/IP 端口。這為用于普通連接的網(wǎng)絡(luò)接口上允許的單個(gè)管理連接提供了一種替代方法,即使已經(jīng)建立了 max_connections 連接。只有在啟動(dòng)時(shí)設(shè)置了 admin_address 系統(tǒng)變量以指示管理接口的 IP 地址時(shí),該接口才可用。如果未指定 admin_address 值,則服務(wù)器不維護(hù)管理界面。
只有SERVICE_CONNECTION_ADMIN 權(quán)限的用戶才允許連接。沒(méi)有限制管理連接的數(shù)量。 MySQL 服務(wù)器使用 DNS(域名系統(tǒng))來(lái)解析使用 TCP/IP 協(xié)議連接的客戶端主機(jī)的名稱,并將它們存儲(chǔ)在主機(jī)緩存中。對(duì)于在名稱解析過(guò)程中出現(xiàn)性能問(wèn)題的大型網(wǎng)絡(luò),請(qǐng)使用 --skip-name-resolve 選項(xiàng)禁用 DNS 或增加 --host-cache-size 選項(xiàng)的值。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
mysql 截取指定的兩個(gè)字符串之間的內(nèi)容
今天我同事在用mysql的時(shí)候,需要對(duì)一個(gè)字符串中的指定內(nèi)容進(jìn)行截取2009-07-07mysql創(chuàng)建數(shù)據(jù)庫(kù),添加用戶,用戶授權(quán)實(shí)操方法
在本篇文章里小編給大家整理的是關(guān)于mysql創(chuàng)建數(shù)據(jù)庫(kù),添加用戶,用戶授權(quán)實(shí)操方法相關(guān)知識(shí)點(diǎn),需要的朋友們學(xué)習(xí)下。2019-10-10MySQL創(chuàng)建唯一索引時(shí)報(bào)錯(cuò)Duplicate?entry?*?for?key問(wèn)題
這篇文章主要介紹了MySQL創(chuàng)建唯一索引時(shí)報(bào)錯(cuò)Duplicate?entry?*?for?key問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09論一條select語(yǔ)句在MySQL是怎樣執(zhí)行的
本文將建立一套建立一套MySQL的知識(shí)框架,通過(guò)討論select語(yǔ)句在MySQL是怎樣執(zhí)行的來(lái)展開(kāi)內(nèi)容,感興趣的小伙伴一起來(lái)看下文吧2021-08-08Mysql連接join查詢?cè)碇R(shí)點(diǎn)
在本文里我們給大家整理了一篇關(guān)于Mysql連接join查詢?cè)碇R(shí)點(diǎn)文章,對(duì)此感興趣的朋友們可以學(xué)習(xí)下。2019-02-02CentOS 7中升級(jí)MySQL 5.7.23的坑與解決方法
我們?cè)诎惭b升級(jí)的時(shí)候會(huì)遇到一些問(wèn)題,不過(guò)可能每個(gè)人遇到的問(wèn)題不一樣,多找找才能解決問(wèn)題喲,下面這篇文章主要給大家介紹了關(guān)于在CentOS 7中升級(jí)MySQL 5.7.23遇到的一個(gè)坑與解決方法,需要的朋友可以參考下2018-10-10