MySQL8.0連接協(xié)議及3306、33060、33062端口的作用解析
一、MySQL連接層
連接層為每個連接維護一個線程。該線程處理查詢執(zhí)行。 在連接可以開始發(fā)送 SQL 查詢之前,連接由驗證用戶名、密碼和客戶端主機。
連接層通過多種連接協(xié)議接受來自應用程序的連接:
- TCP/IP
- UNIX 套接字
- 共享內存
- 命名管道
如下圖所示:
二、連接協(xié)議
協(xié)議在客戶端庫和驅動程序中實現。
連接協(xié)議的速度因本地設置而異。
除了舊版 MySQL 經典協(xié)議之外,MySQL X 協(xié)議還引入了MySQL 5.7.12 并在 MySQL 8.0 中默認啟用。
MySQL 使用 TCP 將消息從客戶端通過網絡傳輸到服務器,可以使用以 mysqlx 為前綴的變量和選項來配置 MySQL X 協(xié)議。
mysqlx 變量的一些示例:
- • mysqlx
- • mysqlx_bind_address
- • mysqlx_max_connections
- • mysqlx_port
- • mysqlx_socket
三、本地和遠程連接協(xié)議:TCP/IP
TCP/IP(傳輸控制協(xié)議/互聯(lián)網協(xié)議):
1、是用于連接 Internet 上的主機的連接協(xié)議套件
2、使用 IP 地址或 DNS 主機名來識別主機
3、使用 TCP 端口號來標識每個主機上的特定服務
MySQL 默認 TCP 端口號:
1、3306 用于 MySQL Classic 協(xié)議(服務器端口選項)
2、33060 用于 MySQL X 協(xié)議(服務器 mysqlx_port 選項)
3、33062 用于使用 MySQL Classic 協(xié)議的管理連接(服務器 admin_port 選項)
修改my.cnf
admin_address='localhost'
修改前后對比:
[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>
網絡監(jiān)聽情況:
[root@hadoop1 ~]# netstat -anltp | grep 33062 tcp 0 0 127.0.0.1:33062 0.0.0.0:* LISTEN 1104641/mysqld [root@hadoop1 ~]#
設置最大連接數方便測試:
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 開始,MySQL 服務器允許專門為管理連接配置 TCP/IP 端口。這為用于普通連接的網絡接口上允許的單個管理連接提供了一種替代方法,即使已經建立了 max_connections 連接。只有在啟動時設置了 admin_address 系統(tǒng)變量以指示管理接口的 IP 地址時,該接口才可用。如果未指定 admin_address 值,則服務器不維護管理界面。
只有SERVICE_CONNECTION_ADMIN 權限的用戶才允許連接。沒有限制管理連接的數量。 MySQL 服務器使用 DNS(域名系統(tǒng))來解析使用 TCP/IP 協(xié)議連接的客戶端主機的名稱,并將它們存儲在主機緩存中。對于在名稱解析過程中出現性能問題的大型網絡,請使用 --skip-name-resolve 選項禁用 DNS 或增加 --host-cache-size 選項的值。
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
mysql創(chuàng)建數據庫,添加用戶,用戶授權實操方法
在本篇文章里小編給大家整理的是關于mysql創(chuàng)建數據庫,添加用戶,用戶授權實操方法相關知識點,需要的朋友們學習下。2019-10-10MySQL創(chuàng)建唯一索引時報錯Duplicate?entry?*?for?key問題
這篇文章主要介紹了MySQL創(chuàng)建唯一索引時報錯Duplicate?entry?*?for?key問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09CentOS 7中升級MySQL 5.7.23的坑與解決方法
我們在安裝升級的時候會遇到一些問題,不過可能每個人遇到的問題不一樣,多找找才能解決問題喲,下面這篇文章主要給大家介紹了關于在CentOS 7中升級MySQL 5.7.23遇到的一個坑與解決方法,需要的朋友可以參考下2018-10-10