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用户都登录数据库,就很难做故障定位了,去解决连接不足的问题。

cc686d89c69a0b8511e657bf3ac10e31.png

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个。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值