mysql8修改默认端口(MySQL 8.0新特性 — 管理端口的使用简介)
mysql8修改默认端口
MySQL 8.0新特性 — 管理端口的使用简介前言
下面这个报错,相信大多数童鞋都遇见过;那么碰到这个问题,我们应该怎么办呢?在mysql 5.7及之前版本,出现“too many connection”报错,超级用户root也无法登录上去,除了重启实例,没有其他更好的解决办法;不过在mysql 8.0版本中,是对连接管理做了一些优化,下面我们就来看一下。
|
error 1040 (hy000): too many connections |
连接管理
在mysql 8.0版本中,对连接管理这一块,是先后做了两个比较大的改变:一个是允许额外连接,另一个是专用的管理端口。
额外连接
在mysql 8.0版本中,在当前连接数达到最大连接数时,服务端允许1个额外连接,可以让具有connection_admin权限的用户连接进来,下面简单测试一下。
(1)为了方便测试,先调整最大连接数
|
mysql> set global max_connections=3; query ok, 0 rows affected (0.00 sec) |
(2)多开几个会话,以达到最大连接数
|
mysql> show processlist; + ----+-----------------+-----------------+------+---------+--------+------------------------+------------------+ | id | user | host | db | command | time | state | info | + ----+-----------------+-----------------+------+---------+--------+------------------------+------------------+ | 15 | event_scheduler | localhost | null | daemon | 154190 | waiting on empty queue | null | | 54 | root | localhost | null | query | 0 | starting | show processlist | | 55 | test | 127.0.0.1:59120 | null | sleep | 19 | | null | | 56 | test | 127.0.0.1:59136 | null | sleep | 9 | | null | + ----+-----------------+-----------------+------+---------+--------+------------------------+------------------+ 4 rows in set (0.00 sec) mysql> show global status like 'threads_connected' ; + -------------------+-------+ | variable_name | value | + -------------------+-------+ | threads_connected | 3 | + -------------------+-------+ 4 rows in set (0.01 sec) |
(3)普通用户test尝试连接,报错too many connections
|
$ mysql -utest -p -h127.0.0.1 -p10080 enter password : error 1040 (08004): too many connections |
(4)超级用户root尝试连接成功
|
$ mysql -uroot -p enter password : welcome to the mysql monitor. commands end with ; or \g. your mysql connection id is 60 server version: 8.0.20 mysql community server - gpl copyright (c) 2000, 2020, oracle and / or its affiliates. all rights reserved. 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> |
(5)再次查看当前连接数,为max_connections+1
|
+ ----+-----------------+-----------------+------+---------+--------+------------------------+------------------+ | id | user | host | db | command | time | state | info | + ----+-----------------+-----------------+------+---------+--------+------------------------+------------------+ | 15 | event_scheduler | localhost | null | daemon | 155064 | waiting on empty queue | null | | 54 | root | localhost | null | query | 0 | starting | show processlist | | 55 | test | 127.0.0.1:59120 | null | sleep | 893 | | null | | 56 | test | 127.0.0.1:59136 | null | sleep | 883 | | null | | 60 | root | localhost | null | sleep | 141 | | null | + ----+-----------------+-----------------+------+---------+--------+------------------------+------------------+ 5 rows in set (0.00 sec) mysql> show global status like 'threads_connected' ; + -------------------+-------+ | variable_name | value | + -------------------+-------+ | threads_connected | 4 | + -------------------+-------+ 4 rows in set (0.00 sec) |
(6)超级用户root再次尝试连接,也报错too many connections
|
$ mysql -uroot -p enter password : error 1040 (hy000): too many connections |
通过上面测试可知,在mysql 8.0中,允许的连接数为max_connections+1,其中这1个额外连接,只允许具有connection_admin权限的用户使用。通过这1个额外连接,dba可以使用超级用户root连接,进行kill会话等管理操作,以避免直接重启实例,降低成本,提高效率。
管理端口
额外连接,在一定程度上,提供了出现too many connection问题时的临时解决手段,但额外数量只有1个,难免会有一些意外,出现类似"连接被抢用"、“终端异常掉线”等情况。因此,在mysql 8.0.14版本中,又推出了一个非常重要的新特性——管理端口;它允许具有service_connection_admin权限的用户,通过特定的ip和port连接上来,且没有连接数限制。
(1)先介绍下相关参数
|
admin_address:监听ip地址 admin_port:监听端口 create_admin_listener_thread:是否创建一个单独的线程来监听管理连接 |
(2)通过配置上述参数,即可启用管理端口
|
mysql> show global variables like 'admin%' ; + ---------------+-----------+ | variable_name | value | + ---------------+-----------+ | admin_address | 127.0.0.1 | | admin_port | 33062 | + ---------------+-----------+ 2 rows in set (0.00 sec) # netstat -lntp | grep 33062 tcp 0 0 127.0.0.1:33062 0.0.0.0:* listen 20042/mysqld |
(3)接下来进行测试
|
mysql> show processlist; + ----+-----------------+-----------------+------+---------+--------+------------------------+------------------+ | id | user | host | db | command | time | state | info | + ----+-----------------+-----------------+------+---------+--------+------------------------+------------------+ | 15 | event_scheduler | localhost | null | daemon | 168750 | waiting on empty queue | null | | 54 | root | localhost | null | query | 0 | starting | show processlist | | 55 | test | 127.0.0.1:59120 | null | sleep | 14579 | | null | | 56 | test | 127.0.0.1:59136 | null | sleep | 14569 | | null | + ----+-----------------+-----------------+------+---------+--------+------------------------+------------------+ 4 rows in set (0.00 sec) mysql> show global status like 'threads_connected' ; + -------------------+-------+ | variable_name | value | + -------------------+-------+ | threads_connected | 3 | + -------------------+-------+ 1 row in set (0.00 sec) |
(4)普通用户test尝试连接,报错too many connections
|
$ mysql -utest -p -h127.0.0.1 -p10080 enter password : error 1040 (08004): too many connections |
(5)超级用户root尝试通过管理端口连接成功
|
$ mysql -uroot -p -h127.0.0.1 -p33062 enter password : welcome to the mysql monitor. commands end with ; or \g. your mysql connection id is 62 server version: 8.0.20 mysql community server - gpl copyright (c) 2000, 2020, oracle and / or its affiliates. all rights reserved. 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> |
(6)继续多开几个会话,使用超级用户root,通过管理端口连接成功,不受最大连接数max_connections限制
|
mysql> show processlist; + ----+-----------------+-----------------+------+---------+--------+------------------------+------------------+ | id | user | host | db | command | time | state | info | + ----+-----------------+-----------------+------+---------+--------+------------------------+------------------+ | 15 | event_scheduler | localhost | null | daemon | 169035 | waiting on empty queue | null | | 54 | root | localhost | null | query | 0 | starting | show processlist | | 55 | test | 127.0.0.1:59120 | null | sleep | 14864 | | null | | 56 | test | 127.0.0.1:59136 | null | sleep | 14854 | | null | | 62 | root | 127.0.0.1:47660 | null | sleep | 151 | | null | | 63 | root | 127.0.0.1:47760 | null | sleep | 52 | | null | | 64 | root | 127.0.0.1:47768 | null | sleep | 43 | | null | | 65 | root | 127.0.0.1:47780 | null | sleep | 35 | | null | | 66 | root | 127.0.0.1:47790 | null | sleep | 24 | | null | | 67 | root | 127.0.0.1:47800 | null | sleep | 16 | | null | | 68 | root | 127.0.0.1:47808 | null | sleep | 8 | | null | + ----+-----------------+-----------------+------+---------+--------+------------------------+------------------+ 11 rows in set (0.00 sec) mysql> show global status like 'threads_connected' ; + -------------------+-------+ | variable_name | value | + -------------------+-------+ | threads_connected | 10 | + -------------------+-------+ 1 row in set (0.00 sec) |
可以说,有了管理端口这个新功能,dba再也不用担心too many connections的问题。
总结
在mysql 8.0版本中,为了应对too many connections的场景,先后推出了额外连接和管理端口两个新功能,可以让dba方便、快速地解决问题;不过,这始终是一个临时应急手段,最根本的原因还是要排查应用端的配置(并发限流、sql性能、连接池配置等等),以彻底规避此类问题。
以上就是mysql 8.0新特性 — 管理端口的使用简介的详细内容,更多关于mysql 8.0新特性 — 管理端口的资料请关注开心学习网其它相关文章!
原文链接:https://cloud.tencent.com/developer/inventory/2098/article/1708462
- mysql8.0查询操作(MySQL 8.0 redo log的深入解析)
- mysql8.0.15官方最新版本安装教程(MySQL8.0.24版本Release Note的一些改进点)
- 怎么知道sqlyog连接的哪个mysql(SQLyog连接MySQL8.0报2058错误的完美解决方法)
- mysql8.0如何配超时时间(解决MySQL8.0时区的问题步骤)
- centos如何安装mysql8.0版本(Centos7下安装MySQL8.0.23的步骤小白入门级别)
- mysql8.0.12安装教程图解(MySql8.023安装过程图文详解首次安装)
- idea安装mybatis(IDEA使用mybatis-generator及配上mysql8.0.3版本遇到的bug)
- mysql8.0配置优化参数(MySQL 8.0 新特性之检查约束的实现)
- mysql常用存储方案及基本原理(详解分析MySQL8.0的内存消耗)
- cent os7.0 安装mysql(mysql8.0.23 linuxcentos7安装完整超详细教程)
- mysql8.0中如何导入数据(mysql8.0.20数据目录迁移的方法)
- mysql8.0设置root密码(MySQL8.0.23版本的root密码重置最优解法)
- 如何打开mysql8.0客户端服务(MySQL mysqladmin客户端的使用简介)
- mysql8.0关键字段使用(MySQL 8.0新特性之隐藏字段的深入讲解)
- mysql的默认数据库例子在哪里(修改MySQL8.0 默认的数据目录快捷操作无配置)
- mysql8.0.19.0正确安装图解(MySQL 8.0.23 主要更新一览新特征解读)
- 快乐是什么(快乐就是)
- 东南亚有哪个国家(东南亚有哪个国家最发达)
- 东南亚安全吗(好不好挣钱)
- 潘长江小品《照亮全家福》台词剧本完整版(潘长江小品照亮全家福台词剧本完整版)
- 一窗通办政务服务小品剧本(一窗通办政务服务小品剧本)
- 刘韬涛丁子贺小品《根治低头族》台词剧本(刘韬涛丁子贺小品根治低头族台词剧本)
热门推荐
- 怎么在当前目录调用python库(Python父目录、子目录的相互调用方法)
- canvas时钟代码(canvas实现烟花的示例代码)
- smart组件详解(Smarty模板类内部原理实例分析)
- 用javascript设计五子棋(JavaScript实现网页版五子棋游戏)
- nginx keepalived配置(Nginx+Keepalived实现Web服务器高可用)
- python中怎么连接mysql(python远程连接MySQL数据库)
- 用python3.5.3实现邮件收发(Python使用POP3和SMTP协议收发邮件的示例代码)
- linux 安装securecrt(Linux SecureCRT显示乱码解决方案)
- docker-compose 如何启动(docker compose部署主从复制的实现)
- vue多个对象实现双向数据绑定(利用js实现Vue2.0中数据的双向绑定功能)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9