mysql 管理端口_MySQL8新增管理端口
簡介
用過MySQL數據庫朋友一定對“ERROR 1040 (HY000): Too many connections”,這個報錯不陌生,出現這個報錯的原因有兩種情況,一種是單個用戶的連接數超過“max_user_connections”參數定義值,另外一種情況是,所有應用的連接數超過“max_connections”參數定義值。
如果是第二種情況,MySQL數據庫還提供一個額外連接,這個連接只有super角色的用戶能登錄,例如root用戶,使用root用戶登錄數據庫之后,就可以進行故障定位。但是如果由于管理不規范,應用程序使用了super角色用戶連接數據,當出現“ERROR 1040 (HY000): Too many connections”報錯之后,大家想想,會發生什么,這個時候DBA使用root用戶都登錄數據庫,就很難做故障定位了,去解決連接不足的問題。
MySQL8新增管理端口
在MySQL8以前的版本,由于應用用戶和管理用戶共同使用同一個端口服務,沒有進行隔離,如果使用不規范時,很容易造成DBA無法用root用戶連接數據庫,進行故障定位。
到MySQL8的版本,MySQL官方考慮到這個問題,于是就給數據庫管理人員獨立起了一個管理端口服務,這樣應用用戶和管理用戶訪問的端口進行隔離,互不影響。
MySQL8管理端口啟用
要啟用MySQL8管理端口,只需要在my.cnf配置文件中添加3個參數admin_address=127.0.0.1admin_port=33306create_admin_listener_thread=1mysql> show variables like '%admin%';+---------------------------------+-------------------------------+| Variable_name | Value |+---------------------------------+-------------------------------+| admin_address | 127.0.0.1 || admin_port | 33306 || 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,TLSv1.1,TLSv1.2,TLSv1.3 || create_admin_listener_thread | ON || log_slow_admin_statements | OFF || persist_only_admin_x509_subject | |+---------------------------------+-------------------------------+14 rows in set (0.01 sec)
下面就來測試一下,當報"ERROR 1040 (HY000): Too many connections"錯誤之后,DBA是否還能使用管理端口連接數據庫
1.模擬會話總數已經達到max_connections參數定義閥值mysql> show variables like '%connections%';+------------------------+-------+| Variable_name | Value |+------------------------+-------+| max_connections | 3 || max_user_connections | 2 || mysqlx_max_connections | 100 |+------------------------+-------+3 rows in set (0.01 sec)mysql> show global status like 'Threads_connected';+-------------------+-------+| Variable_name | Value |+-------------------+-------+| Threads_connected | 3 |+-------------------+-------+1 row in set (0.01 sec)
2.使用MySQL數據庫額外提供的端口,root連接數據庫root@19dd973af376:~# mysql -uroot -prootmysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 32Server version: 8.0.21 MySQL Community Server - GPLCopyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show global status like 'Threads_connected';+-------------------+-------+| Variable_name | Value |+-------------------+-------+| Threads_connected | 4 |+-------------------+-------+1 row in set (0.01 sec)
此時,root用戶已經使用了MySQL數據庫的額外連接,如果再使用root用戶連接數據,就會報錯了root@19dd973af376:~# mysql -uroot -prootmysql: [Warning] Using a password on the command line interface can be insecure.ERROR 1040 (HY000): Too many connections
3.使用管理端口連接數據庫root@19dd973af376:~# mysql -uroot -proot -P 33306 -h127.0.0.1mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 33Server version: 8.0.21 MySQL Community Server - GPLCopyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show global status like 'Threads_connected';+-------------------+-------+| Variable_name | Value |+-------------------+-------+| Threads_connected | 5 |+-------------------+-------+1 row in set (0.03 sec)
可以看到root用戶還可以通過管理端口33306進行登錄了,當前的連接數總數也到了5個,超過了max_connections定義的3個。
總結
以上是生活随笔為你收集整理的mysql 管理端口_MySQL8新增管理端口的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java getbasicremote_
- 下一篇: java 集合数组初始化_Java用Ar